1
1
'use strict' ;
2
-
3
- const util = require ( 'util' ) ;
4
- const internalUtil = require ( 'internal/util' ) ;
5
- const EventEmitter = require ( 'events' ) ;
6
-
7
-
8
2
exports . IncomingMessage = require ( '_http_incoming' ) . IncomingMessage ;
9
3
10
-
11
- const common = require ( '_http_common' ) ;
12
- exports . METHODS = common . methods . slice ( ) . sort ( ) ;
13
-
14
-
15
4
exports . OutgoingMessage = require ( '_http_outgoing' ) . OutgoingMessage ;
16
5
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 ;
17
11
18
12
const server = require ( '_http_server' ) ;
19
13
exports . ServerResponse = server . ServerResponse ;
20
14
exports . STATUS_CODES = server . STATUS_CODES ;
15
+ exports . _connectionListener = server . _connectionListener ;
16
+ const Server = exports . Server = server . Server ;
21
17
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
+ } ;
26
21
27
22
const client = require ( '_http_client' ) ;
28
23
const ClientRequest = exports . ClientRequest = client . ClientRequest ;
@@ -36,64 +31,3 @@ exports.get = function(options, cb) {
36
31
req . end ( ) ;
37
32
return req ;
38
33
} ;
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