Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process 100, 102-199 status codes according to specs. #18033

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/api/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ const options = {
path: '/length_request'
};

// make a request
// Make a request
const req = http.request(options);
req.end();

Expand Down
9 changes: 0 additions & 9 deletions lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,6 @@ function socketOnData(d) {
}
}

// client
function statusIsInformational(status) {
// 100 (Continue) RFC7231 Section 6.2.1
// 102 (Processing) RFC2518
Expand Down Expand Up @@ -496,14 +495,6 @@ function parserOnIncomingClient(res, shouldKeepAlive) {
return 2; // Skip body and treat as Upgrade.
}

// Responses to HEAD requests are crazy.
// HEAD responses aren't allowed to have an entity-body
// but *can* have a content-length which actually corresponds
// to the content-length of the entity-body had the request
// been a GET.
var isHeadResponse = req.method === 'HEAD';
debug('AGENT isHeadResponse', isHeadResponse);

if (statusIsInformational(res.statusCode)) {
// Restart the parser, as this is a 1xx informational message.
req.res = null; // Clear res so that we don't hit double-responses.
Expand Down
15 changes: 8 additions & 7 deletions test/parallel/test-http-information-processing.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
'use strict';
require('../common');
const common = require('../common');
const assert = require('assert');
const http = require('http');
const Countdown = require('../common/countdown');

const test_res_body = 'other stuff!\n';
let processing_count = 0;
const countdown = new Countdown(3, common.mustCall(() => server.close()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Countdown is already a mustCall the wrapping is therefore not necessary :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


const server = http.createServer((req, res) => {
console.error('Server sending informational message #1...');
Expand All @@ -31,21 +32,21 @@ server.listen(0, function() {

req.on('information', function(res) {
console.error('Client got 102 Processing...');
processing_count++;
countdown.dec();
});

req.on('response', function(res) {
assert.strictEqual(processing_count, 2,
assert.strictEqual(countdown.remaining, 1,
'Full response received before all 102 Processing');
assert.strictEqual(200, res.statusCode,
`Final status code was ${res.statusCode}, not 200.`);
res.setEncoding('utf8');
res.on('data', function(chunk) { body += chunk; });
res.on('end', function() {
console.error('Got full response.');
assert.strictEqual(body, test_res_body, 'Response body doesn\'t match.');
assert.ok('abcd' in res.headers, 'Response headers missing.');
server.close();
assert.strictEqual(body, test_res_body);
assert.ok('abcd' in res.headers);
countdown.dec();
});
});
});