11'use strict' ;
2-
3- const util = require ( 'util' ) ;
4- const internalUtil = require ( 'internal/util' ) ;
5- const EventEmitter = require ( 'events' ) ;
6-
7-
82exports . IncomingMessage = require ( '_http_incoming' ) . IncomingMessage ;
93
10-
11- const common = require ( '_http_common' ) ;
12- exports . METHODS = common . methods . slice ( ) . sort ( ) ;
13-
14-
154exports . OutgoingMessage = require ( '_http_outgoing' ) . OutgoingMessage ;
165
6+ exports . METHODS = require ( '_http_common' ) . methods . slice ( ) . sort ( ) ;
7+
8+ const agent = require ( '_http_agent' ) ;
9+ exports . Agent = agent . Agent ;
10+ exports . globalAgent = agent . globalAgent ;
1711
1812const server = require ( '_http_server' ) ;
1913exports . ServerResponse = server . ServerResponse ;
2014exports . STATUS_CODES = server . STATUS_CODES ;
15+ exports . _connectionListener = server . _connectionListener ;
16+ const Server = exports . Server = server . Server ;
2117
22-
23- const agent = require ( '_http_agent' ) ;
24- const Agent = exports . Agent = agent . Agent ;
25- exports . globalAgent = agent . globalAgent ;
18+ exports . createServer = function ( requestListener ) {
19+ return new Server ( requestListener ) ;
20+ } ;
2621
2722const client = require ( '_http_client' ) ;
2823const ClientRequest = exports . ClientRequest = client . ClientRequest ;
@@ -36,64 +31,3 @@ exports.get = function(options, cb) {
3631 req . end ( ) ;
3732 return req ;
3833} ;
39-
40- exports . _connectionListener = server . _connectionListener ;
41- const Server = exports . Server = server . Server ;
42-
43- exports . createServer = function ( requestListener ) {
44- return new Server ( requestListener ) ;
45- } ;
46-
47-
48- // Legacy Interface
49-
50- function Client ( port , host ) {
51- if ( ! ( this instanceof Client ) ) return new Client ( port , host ) ;
52- EventEmitter . call ( this ) ;
53-
54- host = host || 'localhost' ;
55- port = port || 80 ;
56- this . host = host ;
57- this . port = port ;
58- this . agent = new Agent ( { host : host , port : port , maxSockets : 1 } ) ;
59- }
60- util . inherits ( Client , EventEmitter ) ;
61- Client . prototype . request = function ( method , path , headers ) {
62- var self = this ;
63- var options = { } ;
64- options . host = self . host ;
65- options . port = self . port ;
66- if ( method [ 0 ] === '/' ) {
67- headers = path ;
68- path = method ;
69- method = 'GET' ;
70- }
71- options . method = method ;
72- options . path = path ;
73- options . headers = headers ;
74- options . agent = self . agent ;
75- var c = new ClientRequest ( options ) ;
76- c . on ( 'error' , function ( e ) {
77- self . emit ( 'error' , e ) ;
78- } ) ;
79- // The old Client interface emitted 'end' on socket end.
80- // This doesn't map to how we want things to operate in the future
81- // but it will get removed when we remove this legacy interface.
82- c . on ( 'socket' , function ( s ) {
83- s . on ( 'end' , function ( ) {
84- if ( self . _decoder ) {
85- var ret = self . _decoder . end ( ) ;
86- if ( ret )
87- self . emit ( 'data' , ret ) ;
88- }
89- self . emit ( 'end' ) ;
90- } ) ;
91- } ) ;
92- return c ;
93- } ;
94-
95- exports . Client = internalUtil . deprecate ( Client , 'http.Client is deprecated.' ) ;
96-
97- exports . createClient = internalUtil . deprecate ( function ( port , host ) {
98- return new Client ( port , host ) ;
99- } , 'http.createClient is deprecated. Use http.request instead.' ) ;
0 commit comments