Skip to content
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
35 changes: 6 additions & 29 deletions lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const closeExpression = /close/i;
const contentLengthExpression = /^Content-Length$/i;
const dateExpression = /^Date$/i;
const expectExpression = /^Expect$/i;
const trailerExpression = /^Trailer$/i;

const automaticHeaders = {
connection: true,
Expand Down Expand Up @@ -57,7 +56,6 @@ function OutgoingMessage() {
this.sendDate = false;
this._removedHeader = {};

this._contentLength = null;
this._hasBody = true;
this._trailer = '';

Expand Down Expand Up @@ -187,7 +185,6 @@ OutgoingMessage.prototype._storeHeader = function(firstLine, headers) {
sentTransferEncodingHeader: false,
sentDateHeader: false,
sentExpect: false,
sentTrailer: false,
messageHeader: firstLine
};

Expand Down Expand Up @@ -260,26 +257,16 @@ OutgoingMessage.prototype._storeHeader = function(firstLine, headers) {

if (state.sentContentLengthHeader === false &&
state.sentTransferEncodingHeader === false) {
if (!this._hasBody) {
// Make sure we don't end the 0\r\n\r\n at the end of the message.
this.chunkedEncoding = false;
} else if (!this.useChunkedEncodingByDefault) {
this._last = true;
} else {
if (!state.sentTrailer &&
!this._removedHeader['content-length'] &&
typeof this._contentLength === 'number') {
state.messageHeader += 'Content-Length: ' + this._contentLength +
'\r\n';
} else if (!this._removedHeader['transfer-encoding']) {
if (this._hasBody && !this._removedHeader['transfer-encoding']) {
if (this.useChunkedEncodingByDefault) {
state.messageHeader += 'Transfer-Encoding: chunked\r\n';
this.chunkedEncoding = true;
} else {
// We should only be able to get here if both Content-Length and
// Transfer-Encoding are removed by the user.
// See: test/parallel/test-http-remove-header-stays-removed.js
debug('Both Content-Length and Transfer-Encoding are removed');
this._last = true;
}
} else {
// Make sure we don't end the 0\r\n\r\n at the end of the message.
this.chunkedEncoding = false;
}
}

Expand Down Expand Up @@ -317,8 +304,6 @@ function storeHeader(self, state, field, value) {
state.sentDateHeader = true;
} else if (expectExpression.test(field)) {
state.sentExpect = true;
} else if (trailerExpression.test(field)) {
state.sentTrailer = true;
}
}

Expand Down Expand Up @@ -524,14 +509,6 @@ OutgoingMessage.prototype.end = function(data, encoding, callback) {
this.once('finish', callback);

if (!this._header) {
if (data) {
if (typeof data === 'string')
this._contentLength = Buffer.byteLength(data, encoding);
else
this._contentLength = data.length;
} else {
this._contentLength = 0;
}
this._implicitHeader();
}

Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-http-automatic-headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var http = require('http');
var server = http.createServer(function(req, res) {
res.setHeader('X-Date', 'foo');
res.setHeader('X-Connection', 'bar');
res.setHeader('X-Content-Length', 'baz');
res.setHeader('X-Transfer-Encoding', 'baz');
res.end();
});
server.listen(common.PORT);
Expand All @@ -20,10 +20,10 @@ server.on('listening', function() {
assert.equal(res.statusCode, 200);
assert.equal(res.headers['x-date'], 'foo');
assert.equal(res.headers['x-connection'], 'bar');
assert.equal(res.headers['x-content-length'], 'baz');
assert.equal(res.headers['x-transfer-encoding'], 'baz');
assert(res.headers['date']);
assert.equal(res.headers['connection'], 'keep-alive');
assert.equal(res.headers['content-length'], '0');
assert.equal(res.headers['transfer-encoding'], 'chunked');
server.close();
agent.destroy();
});
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-http-client-default-headers-exist.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ var expectedHeaders = {
'GET': ['host', 'connection'],
'HEAD': ['host', 'connection'],
'OPTIONS': ['host', 'connection'],
'POST': ['host', 'connection', 'content-length'],
'PUT': ['host', 'connection', 'content-length']
'POST': ['host', 'connection', 'transfer-encoding'],
'PUT': ['host', 'connection', 'transfer-encoding']
};

var expectedMethods = Object.keys(expectedHeaders);
Expand Down
89 changes: 0 additions & 89 deletions test/parallel/test-http-content-length.js

This file was deleted.

6 changes: 1 addition & 5 deletions test/parallel/test-http-raw-headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ http.createServer(function(req, res) {
});

req.resume();
res.setHeader('Trailer', 'x-foo');
res.addTrailers([
['x-fOo', 'xOxOxOx'],
['x-foO', 'OxOxOxO'],
Expand Down Expand Up @@ -73,8 +72,6 @@ http.createServer(function(req, res) {
req.end('y b a r');
req.on('response', function(res) {
var expectRawHeaders = [
'Trailer',
'x-foo',
'Date',
null,
'Connection',
Expand All @@ -83,12 +80,11 @@ http.createServer(function(req, res) {
'chunked'
];
var expectHeaders = {
trailer: 'x-foo',
date: null,
connection: 'close',
'transfer-encoding': 'chunked'
};
res.rawHeaders[3] = null;
res.rawHeaders[1] = null;
res.headers.date = null;
assert.deepEqual(res.rawHeaders, expectRawHeaders);
assert.deepEqual(res.headers, expectHeaders);
Expand Down
1 change: 0 additions & 1 deletion test/parallel/test-http-remove-header-stays-removed.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ var server = http.createServer(function(request, response) {
// to the output:
response.removeHeader('connection');
response.removeHeader('transfer-encoding');
response.removeHeader('content-length');

// make sure that removing and then setting still works:
response.removeHeader('date');
Expand Down