Skip to content

Commit 675cffb

Browse files
tellnesbrendanashworth
authored andcommitted
http: don't confuse automatic headers for others
If you set a custom http header which includes eg. the string `Date`, then http will not automatically send the `Date` header. This is also true for other automatic http headers. PR-URL: #828 Reviewed-By: Brendan Ashworth <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
1 parent 25da074 commit 675cffb

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

lib/_http_outgoing.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ const CRLF = common.CRLF;
1010
const chunkExpression = common.chunkExpression;
1111
const debug = common.debug;
1212

13-
const connectionExpression = /Connection/i;
14-
const transferEncodingExpression = /Transfer-Encoding/i;
13+
const connectionExpression = /^Connection$/i;
14+
const transferEncodingExpression = /^Transfer-Encoding$/i;
1515
const closeExpression = /close/i;
16-
const contentLengthExpression = /Content-Length/i;
17-
const dateExpression = /Date/i;
18-
const expectExpression = /Expect/i;
16+
const contentLengthExpression = /^Content-Length$/i;
17+
const dateExpression = /^Date$/i;
18+
const expectExpression = /^Expect$/i;
1919

2020
const automaticHeaders = {
2121
connection: true,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
var common = require('../common');
2+
var assert = require('assert');
3+
var http = require('http');
4+
5+
var server = http.createServer(function(req, res) {
6+
res.setHeader('X-Date', 'foo');
7+
res.setHeader('X-Connection', 'bar');
8+
res.setHeader('X-Transfer-Encoding', 'baz');
9+
res.end();
10+
});
11+
server.listen(common.PORT);
12+
13+
server.on('listening', function() {
14+
var agent = new http.Agent({ port: common.PORT, maxSockets: 1 });
15+
http.get({
16+
port: common.PORT,
17+
path: '/hello',
18+
agent: agent
19+
}, function(res) {
20+
assert.equal(res.statusCode, 200);
21+
assert.equal(res.headers['x-date'], 'foo');
22+
assert.equal(res.headers['x-connection'], 'bar');
23+
assert.equal(res.headers['x-transfer-encoding'], 'baz');
24+
assert(res.headers['date']);
25+
assert.equal(res.headers['connection'], 'keep-alive');
26+
assert.equal(res.headers['transfer-encoding'], 'chunked');
27+
server.close();
28+
agent.destroy();
29+
});
30+
});

test/parallel/test-tls-over-http-tunnel.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ var proxy = net.createServer(function(clientSocket) {
4141
// Verify the CONNECT request
4242
assert.equal('CONNECT localhost:' + common.PORT + ' HTTP/1.1\r\n' +
4343
'Proxy-Connections: keep-alive\r\n' +
44-
'Host: localhost:' + proxyPort + '\r\n\r\n',
44+
'Host: localhost:' + proxyPort + '\r\n' +
45+
'Connection: close\r\n\r\n',
4546
chunk);
4647

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

0 commit comments

Comments
 (0)