1
-
2
1
/**
3
2
* Module dependencies.
4
3
*/
@@ -23,10 +22,13 @@ module.exports = HttpsProxyAgent;
23
22
* @api public
24
23
*/
25
24
26
- function HttpsProxyAgent ( opts ) {
25
+ function HttpsProxyAgent ( opts ) {
27
26
if ( ! ( this instanceof HttpsProxyAgent ) ) return new HttpsProxyAgent ( opts ) ;
28
27
if ( 'string' == typeof opts ) opts = url . parse ( opts ) ;
29
- if ( ! opts ) throw new Error ( 'an HTTP(S) proxy server `host` and `port` must be specified!' ) ;
28
+ if ( ! opts )
29
+ throw new Error (
30
+ 'an HTTP(S) proxy server `host` and `port` must be specified!'
31
+ ) ;
30
32
debug ( 'creating new HttpsProxyAgent instance: %o' , opts ) ;
31
33
Agent . call ( this , opts ) ;
32
34
@@ -57,7 +59,7 @@ inherits(HttpsProxyAgent, Agent);
57
59
* @api public
58
60
*/
59
61
60
- HttpsProxyAgent . prototype . callback = function connect ( req , opts , fn ) {
62
+ HttpsProxyAgent . prototype . callback = function connect ( req , opts , fn ) {
61
63
var proxy = this . proxy ;
62
64
63
65
// create a socket connection to the proxy server
@@ -75,34 +77,34 @@ HttpsProxyAgent.prototype.callback = function connect (req, opts, fn) {
75
77
var buffers = [ ] ;
76
78
var buffersLength = 0 ;
77
79
78
- function read ( ) {
80
+ function read ( ) {
79
81
var b = socket . read ( ) ;
80
82
if ( b ) ondata ( b ) ;
81
83
else socket . once ( 'readable' , read ) ;
82
84
}
83
85
84
- function cleanup ( ) {
86
+ function cleanup ( ) {
85
87
socket . removeListener ( 'data' , ondata ) ;
86
88
socket . removeListener ( 'end' , onend ) ;
87
89
socket . removeListener ( 'error' , onerror ) ;
88
90
socket . removeListener ( 'close' , onclose ) ;
89
91
socket . removeListener ( 'readable' , read ) ;
90
92
}
91
93
92
- function onclose ( err ) {
94
+ function onclose ( err ) {
93
95
debug ( 'onclose had error %o' , err ) ;
94
96
}
95
97
96
- function onend ( ) {
98
+ function onend ( ) {
97
99
debug ( 'onend' ) ;
98
100
}
99
101
100
- function onerror ( err ) {
102
+ function onerror ( err ) {
101
103
cleanup ( ) ;
102
104
fn ( err ) ;
103
105
}
104
106
105
- function ondata ( b ) {
107
+ function ondata ( b ) {
106
108
buffers . push ( b ) ;
107
109
buffersLength += b . length ;
108
110
var buffered = Buffer . concat ( buffers , buffersLength ) ;
@@ -133,9 +135,12 @@ HttpsProxyAgent.prototype.callback = function connect (req, opts, fn) {
133
135
if ( opts . secureEndpoint ) {
134
136
// since the proxy is connecting to an SSL server, we have
135
137
// to upgrade this socket connection to an SSL connection
136
- debug ( 'upgrading proxy-connected socket to TLS connection: %o' , opts . host ) ;
138
+ debug (
139
+ 'upgrading proxy-connected socket to TLS connection: %o' ,
140
+ opts . host
141
+ ) ;
137
142
opts . socket = socket ;
138
- opts . servername = opts . servername ? opts . servername : opts . host ;
143
+ opts . servername = opts . servername || opts . host ;
139
144
opts . host = null ;
140
145
opts . hostname = null ;
141
146
opts . port = null ;
@@ -159,7 +164,7 @@ HttpsProxyAgent.prototype.callback = function connect (req, opts, fn) {
159
164
}
160
165
}
161
166
162
- function onsocket ( socket ) {
167
+ function onsocket ( socket ) {
163
168
// replay the "buffers" Buffer onto the `socket`, since at this point
164
169
// the HTTP module machinery has been hooked up for the user
165
170
if ( 'function' == typeof socket . ondata ) {
@@ -192,11 +197,12 @@ HttpsProxyAgent.prototype.callback = function connect (req, opts, fn) {
192
197
193
198
var headers = Object . assign ( { } , proxy . headers ) ;
194
199
if ( proxy . auth ) {
195
- headers [ 'Proxy-Authorization' ] = 'Basic ' + new Buffer ( proxy . auth ) . toString ( 'base64' ) ;
200
+ headers [ 'Proxy-Authorization' ] =
201
+ 'Basic ' + new Buffer ( proxy . auth ) . toString ( 'base64' ) ;
196
202
}
197
203
headers [ 'Host' ] = hostname ;
198
204
headers [ 'Connection' ] = 'close' ;
199
- Object . keys ( headers ) . forEach ( function ( name ) {
205
+ Object . keys ( headers ) . forEach ( function ( name ) {
200
206
msg += name + ': ' + headers [ name ] + '\r\n' ;
201
207
} ) ;
202
208
0 commit comments