Skip to content

Commit

Permalink
http: misc cleanup and minor optimizations
Browse files Browse the repository at this point in the history
PR-URL: #6533
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
  • Loading branch information
mscdex authored and evanlucas committed Jan 4, 2017
1 parent b094b49 commit 1f0fd7b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
1 change: 0 additions & 1 deletion lib/_http_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ function freeParser(parser, req, socket) {
parser[kOnExecute] = null;
if (parsers.free(parser) === false)
parser.close();
parser = null;
}
if (req) {
req.parser = null;
Expand Down
8 changes: 3 additions & 5 deletions lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,7 @@ OutgoingMessage.prototype.getHeader = function getHeader(name) {

if (!this._headers) return;

var key = name.toLowerCase();
return this._headers[key];
return this._headers[name.toLowerCase()];
};


Expand Down Expand Up @@ -585,7 +584,6 @@ OutgoingMessage.prototype.end = function end(data, encoding, callback) {
if (this.connection && data)
this.connection.cork();

var ret;
if (data) {
// Normal body write.
this.write(data, encoding);
Expand All @@ -598,6 +596,7 @@ OutgoingMessage.prototype.end = function end(data, encoding, callback) {
this.emit('finish');
};

var ret;
if (this._hasBody && this.chunkedEncoding) {
ret = this._send('0\r\n' + this._trailer + '\r\n', 'latin1', finish);
} else {
Expand Down Expand Up @@ -677,8 +676,7 @@ OutgoingMessage.prototype._flushOutput = function _flushOutput(socket) {
var outputCallbacks = this.outputCallbacks;
socket.cork();
for (var i = 0; i < outputLength; i++) {
ret = socket.write(output[i], outputEncodings[i],
outputCallbacks[i]);
ret = socket.write(output[i], outputEncodings[i], outputCallbacks[i]);
}
socket.uncork();

Expand Down
9 changes: 5 additions & 4 deletions lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ function ServerResponse(req) {
if (req.method === 'HEAD') this._hasBody = false;

this.sendDate = true;
this._sent100 = false;
this._expect_continue = false;

if (req.httpVersionMajor < 1 || req.httpVersionMinor < 1) {
this.useChunkedEncodingByDefault = chunkExpression.test(req.headers.te);
Expand Down Expand Up @@ -195,8 +197,7 @@ function writeHead(statusCode, reason, obj) {
if (common._checkInvalidHeaderChar(this.statusMessage))
throw new Error('Invalid character in statusMessage.');

var statusLine = 'HTTP/1.1 ' + statusCode.toString() + ' ' +
this.statusMessage + CRLF;
var statusLine = 'HTTP/1.1 ' + statusCode + ' ' + this.statusMessage + CRLF;

if (statusCode === 204 || statusCode === 304 ||
(100 <= statusCode && statusCode <= 199)) {
Expand Down Expand Up @@ -232,7 +233,7 @@ function Server(requestListener) {
net.Server.call(this, { allowHalfOpen: true });

if (requestListener) {
this.addListener('request', requestListener);
this.on('request', requestListener);
}

/* eslint-disable max-len */
Expand All @@ -242,7 +243,7 @@ function Server(requestListener) {
/* eslint-enable max-len */
this.httpAllowHalfOpen = false;

this.addListener('connection', connectionListener);
this.on('connection', connectionListener);

this.timeout = 2 * 60 * 1000;

Expand Down

0 comments on commit 1f0fd7b

Please sign in to comment.