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

http: don't confuse automatic headers for others #828

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 5 additions & 5 deletions lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ const CRLF = common.CRLF;
const chunkExpression = common.chunkExpression;
const debug = common.debug;

const connectionExpression = /Connection/i;
const transferEncodingExpression = /Transfer-Encoding/i;
const connectionExpression = /^Connection$/i;
const transferEncodingExpression = /^Transfer-Encoding$/i;
const closeExpression = /close/i;
Copy link
Member

Choose a reason for hiding this comment

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

why is this left out?

Copy link
Member

Choose a reason for hiding this comment

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

oh, nmind

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is a possible bug also. Maybe this regexp:

/(^|,(\ )*)close($|,)/i

const contentLengthExpression = /Content-Length/i;
const dateExpression = /Date/i;
const expectExpression = /Expect/i;
const contentLengthExpression = /^Content-Length$/i;
const dateExpression = /^Date$/i;
const expectExpression = /^Expect$/i;

const automaticHeaders = {
connection: true,
Expand Down
30 changes: 30 additions & 0 deletions test/parallel/test-http-automatic-headers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
var common = require('../common');
var assert = require('assert');
var http = require('http');

var server = http.createServer(function(req, res) {
res.setHeader('X-Date', 'foo');
res.setHeader('X-Connection', 'bar');
res.setHeader('X-Transfer-Encoding', 'baz');
res.end();
});
server.listen(common.PORT);

server.on('listening', function() {
var agent = new http.Agent({ port: common.PORT, maxSockets: 1 });
http.get({
port: common.PORT,
path: '/hello',
agent: agent
}, function(res) {
assert.equal(res.statusCode, 200);
assert.equal(res.headers['x-date'], 'foo');
assert.equal(res.headers['x-connection'], 'bar');
assert.equal(res.headers['x-transfer-encoding'], 'baz');
assert(res.headers['date']);
assert.equal(res.headers['connection'], 'keep-alive');
assert.equal(res.headers['transfer-encoding'], 'chunked');
server.close();
agent.destroy();
});
});
3 changes: 2 additions & 1 deletion test/parallel/test-tls-over-http-tunnel.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ var proxy = net.createServer(function(clientSocket) {
// Verify the CONNECT request
assert.equal('CONNECT localhost:' + common.PORT + ' HTTP/1.1\r\n' +
'Proxy-Connections: keep-alive\r\n' +
'Host: localhost:' + proxyPort + '\r\n\r\n',
'Host: localhost:' + proxyPort + '\r\n' +
'Connection: close\r\n\r\n',
Copy link
Contributor

Choose a reason for hiding this comment

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

is this related to the fix?

Copy link
Contributor

Choose a reason for hiding this comment

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

i'd say that if you're going to do that you should remove the Proxy-Connections header also instead of just leaving it there -- but another maintainer might want this change in a separate pull request anyways

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe, but that is not really relevant to this change. The Proxy-Connections header is just like a custom http header and does not mean anything in this context. The plan was not do to unrelated changes in the tests.

chunk);

console.log('PROXY: got CONNECT request');
Expand Down