diff --git a/lib/_http_agent.js b/lib/_http_agent.js index 0661ee155371f5..351417a7ba6a74 100644 --- a/lib/_http_agent.js +++ b/lib/_http_agent.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() +}; diff --git a/lib/_http_client.js b/lib/_http_client.js index b818b05c527e61..a118bbe3aa7405 100644 --- a/lib/_http_client.js +++ b/lib/_http_client.js @@ -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 +}; diff --git a/lib/_http_common.js b/lib/_http_common.js index c2ffbfce804b86..2245ae079acedd 100644 --- a/lib/_http_common.js +++ b/lib/_http_common.js @@ -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 +}; diff --git a/lib/_http_incoming.js b/lib/_http_incoming.js index b0d5c29b2094d4..be724da310f898 100644 --- a/lib/_http_incoming.js +++ b/lib/_http_incoming.js @@ -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 +}; diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index 130adef1de1303..e1fee20cfea6a8 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -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 +}; diff --git a/lib/_http_server.js b/lib/_http_server.js index 0a300ade618c85..2821db8f40c218 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -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 +}; diff --git a/lib/http.js b/lib/http.js index 4b0e589a568956..af3e8a017ce1b9 100644 --- a/lib/http.js +++ b/lib/http.js @@ -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 };