Skip to content
Permalink
Browse files

http: use more efficient module.exports pattern

PR-URL: #11594
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
  • Loading branch information...
jasnell committed Feb 28, 2017
1 parent 2a4a5f0 commit 5425e0dcbee1ed8f6687203eafb7c3cf214f3393
Showing with 70 additions and 48 deletions.
  1. +4 −2 lib/_http_agent.js
  2. +4 −1 lib/_http_client.js
  3. +13 −11 lib/_http_common.js
  4. +6 −6 lib/_http_incoming.js
  5. +5 −0 lib/_http_outgoing.js
  6. +9 −7 lib/_http_server.js
  7. +29 −21 lib/http.js
@@ -105,7 +105,6 @@ function Agent(options) {
}

util.inherits(Agent, EventEmitter);
exports.Agent = Agent;

Agent.defaultMaxSockets = Infinity;

@@ -314,4 +313,7 @@ Agent.prototype.destroy = function destroy() {
}
};

exports.globalAgent = new Agent();
module.exports = {
Agent,
globalAgent: new Agent()
};
@@ -286,7 +286,6 @@ function ClientRequest(options, cb) {

util.inherits(ClientRequest, OutgoingMessage);

exports.ClientRequest = ClientRequest;

ClientRequest.prototype._finish = function _finish() {
DTRACE_HTTP_CLIENT_REQUEST(this, this.connection);
@@ -752,3 +751,7 @@ ClientRequest.prototype.setSocketKeepAlive =
ClientRequest.prototype.clearTimeout = function clearTimeout(cb) {
this.setTimeout(0, cb);
};

module.exports = {
ClientRequest
};
@@ -32,12 +32,6 @@ const readStart = incoming.readStart;
const readStop = incoming.readStop;

const debug = require('util').debuglog('http');
exports.debug = debug;

exports.CRLF = '\r\n';
exports.chunkExpression = /(?:^|\W)chunked(?:$|\W)/i;
exports.continueExpression = /(?:^|\W)100-continue(?:$|\W)/i;
exports.methods = methods;

const kOnHeaders = HTTPParser.kOnHeaders | 0;
const kOnHeadersComplete = HTTPParser.kOnHeadersComplete | 0;
@@ -194,7 +188,6 @@ var parsers = new FreeList('parsers', 1000, function() {

return parser;
});
exports.parsers = parsers;


// Free the parser and also break any links that it
@@ -227,7 +220,6 @@ function freeParser(parser, req, socket) {
socket.parser = null;
}
}
exports.freeParser = freeParser;


function ondrain() {
@@ -239,7 +231,6 @@ function httpSocketSetup(socket) {
socket.removeListener('drain', ondrain);
socket.on('drain', ondrain);
}
exports.httpSocketSetup = httpSocketSetup;

/**
* Verifies that the given val is a valid HTTP token
@@ -306,7 +297,6 @@ function checkIsHttpToken(val) {
}
return true;
}
exports._checkIsHttpToken = checkIsHttpToken;

/**
* True if val contains an invalid field-vchar
@@ -360,4 +350,16 @@ function checkInvalidHeaderChar(val) {
}
return false;
}
exports._checkInvalidHeaderChar = checkInvalidHeaderChar;

module.exports = {
_checkInvalidHeaderChar: checkInvalidHeaderChar,
_checkIsHttpToken: checkIsHttpToken,
chunkExpression: /(?:^|\W)chunked(?:$|\W)/i,
continueExpression: /(?:^|\W)100-continue(?:$|\W)/i,
CRLF: '\r\n',
debug,
freeParser,
httpSocketSetup,
methods,
parsers
};
@@ -28,14 +28,11 @@ function readStart(socket) {
if (socket && !socket._paused && socket.readable)
socket.resume();
}
exports.readStart = readStart;

function readStop(socket) {
if (socket)
socket.pause();
}
exports.readStop = readStop;


/* Abstract base class for ServerRequest and ClientResponse. */
function IncomingMessage(socket) {
@@ -83,9 +80,6 @@ function IncomingMessage(socket) {
util.inherits(IncomingMessage, Stream.Readable);


exports.IncomingMessage = IncomingMessage;


IncomingMessage.prototype.setTimeout = function setTimeout(msecs, callback) {
if (callback)
this.on('timeout', callback);
@@ -324,3 +318,9 @@ IncomingMessage.prototype._dump = function _dump() {
this.resume();
}
};

module.exports = {
IncomingMessage,
readStart,
readStop
};
@@ -887,3 +887,8 @@ OutgoingMessage.prototype.flushHeaders = function flushHeaders() {
OutgoingMessage.prototype.flush = internalUtil.deprecate(function() {
this.flushHeaders();
}, 'OutgoingMessage.flush is deprecated. Use flushHeaders instead.', 'DEP0001');


module.exports = {
OutgoingMessage
};
@@ -36,7 +36,7 @@ const httpSocketSetup = common.httpSocketSetup;
const OutgoingMessage = require('_http_outgoing').OutgoingMessage;
const outHeadersKey = require('internal/http').outHeadersKey;

const STATUS_CODES = exports.STATUS_CODES = {
const STATUS_CODES = {
100: 'Continue',
101: 'Switching Protocols',
102: 'Processing', // RFC 2518, obsoleted by RFC 4918
@@ -128,8 +128,6 @@ ServerResponse.prototype._finish = function _finish() {
};


exports.ServerResponse = ServerResponse;

ServerResponse.prototype.statusCode = 200;
ServerResponse.prototype.statusMessage = undefined;

@@ -290,9 +288,6 @@ Server.prototype.setTimeout = function setTimeout(msecs, callback) {
};


exports.Server = Server;


function connectionListener(socket) {
debug('SERVER new http connection');

@@ -363,7 +358,7 @@ function connectionListener(socket) {

socket._paused = false;
}
exports._connectionListener = connectionListener;


function updateOutgoingData(socket, state, delta) {
state.outgoingData += delta;
@@ -640,3 +635,10 @@ function socketOnWrap(ev, fn) {

return res;
}

module.exports = {
STATUS_CODES,
Server,
ServerResponse,
_connectionListener: connectionListener
};
@@ -20,35 +20,43 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';
exports.IncomingMessage = require('_http_incoming').IncomingMessage;

exports.OutgoingMessage = require('_http_outgoing').OutgoingMessage;

exports.METHODS = require('_http_common').methods.slice().sort();

const agent = require('_http_agent');
exports.Agent = agent.Agent;
exports.globalAgent = agent.globalAgent;

const client = require('_http_client');
const common = require('_http_common');
const incoming = require('_http_incoming');
const outgoing = require('_http_outgoing');
const server = require('_http_server');
exports.ServerResponse = server.ServerResponse;
exports.STATUS_CODES = server.STATUS_CODES;
exports._connectionListener = server._connectionListener;
const Server = exports.Server = server.Server;

exports.createServer = function createServer(requestListener) {
return new Server(requestListener);
};
const Server = server.Server;
const ClientRequest = client.ClientRequest;

const client = require('_http_client');
const ClientRequest = exports.ClientRequest = client.ClientRequest;
function createServer(requestListener) {
return new Server(requestListener);
}

exports.request = function request(options, cb) {
function request(options, cb) {
return new ClientRequest(options, cb);
};
}

exports.get = function get(options, cb) {
var req = exports.request(options, cb);
function get(options, cb) {
var req = request(options, cb);
req.end();
return req;
}

module.exports = {
_connectionListener: server._connectionListener,
METHODS: common.methods.slice().sort(),
STATUS_CODES: server.STATUS_CODES,
Agent: agent.Agent,
ClientRequest,
globalAgent: agent.globalAgent,
IncomingMessage: incoming.IncomingMessage,
OutgoingMessage: outgoing.OutgoingMessage,
Server,
ServerResponse: server.ServerResponse,
createServer,
get,
request
};

0 comments on commit 5425e0d

Please sign in to comment.
You can’t perform that action at this time.