@@ -91,7 +91,6 @@ HttpsProxyAgent.prototype.callback = function connect(req, opts, fn) {
91
91
}
92
92
93
93
function cleanup ( ) {
94
- socket . removeListener ( 'data' , ondata ) ;
95
94
socket . removeListener ( 'end' , onend ) ;
96
95
socket . removeListener ( 'error' , onerror ) ;
97
96
socket . removeListener ( 'close' , onclose ) ;
@@ -120,11 +119,7 @@ HttpsProxyAgent.prototype.callback = function connect(req, opts, fn) {
120
119
if ( ! ~ str . indexOf ( '\r\n\r\n' ) ) {
121
120
// keep buffering
122
121
debug ( 'have not received end of HTTP headers yet...' ) ;
123
- if ( socket . read ) {
124
- read ( ) ;
125
- } else {
126
- socket . once ( 'data' , ondata ) ;
127
- }
122
+ read ( ) ;
128
123
return ;
129
124
}
130
125
@@ -174,11 +169,7 @@ HttpsProxyAgent.prototype.callback = function connect(req, opts, fn) {
174
169
function onsocket ( socket ) {
175
170
// replay the "buffers" Buffer onto the `socket`, since at this point
176
171
// the HTTP module machinery has been hooked up for the user
177
- if ( 'function' == typeof socket . ondata ) {
178
- // node <= v0.11.3, the `ondata` function is set on the socket
179
- socket . ondata ( buffers , 0 , buffers . length ) ;
180
- } else if ( socket . listeners ( 'data' ) . length > 0 ) {
181
- // node > v0.11.3, the "data" event is listened for directly
172
+ if ( socket . listenerCount ( 'data' ) > 0 ) {
182
173
socket . emit ( 'data' , buffers ) ;
183
174
} else {
184
175
// never?
@@ -193,11 +184,7 @@ HttpsProxyAgent.prototype.callback = function connect(req, opts, fn) {
193
184
socket . on ( 'close' , onclose ) ;
194
185
socket . on ( 'end' , onend ) ;
195
186
196
- if ( socket . read ) {
197
- read ( ) ;
198
- } else {
199
- socket . once ( 'data' , ondata ) ;
200
- }
187
+ read ( ) ;
201
188
202
189
var hostname = opts . host + ':' + opts . port ;
203
190
var msg = 'CONNECT ' + hostname + ' HTTP/1.1\r\n' ;
0 commit comments