2
2
* Module dependencies.
3
3
*/
4
4
5
+ var assert = require ( 'assert' ) ;
5
6
var net = require ( 'net' ) ;
6
7
var tls = require ( 'tls' ) ;
7
8
var url = require ( 'url' ) ;
8
- var events = require ( 'events ' ) ;
9
+ var stream = require ( 'stream ' ) ;
9
10
var Agent = require ( 'agent-base' ) ;
10
11
var inherits = require ( 'util' ) . inherits ;
11
12
var debug = require ( 'debug' ) ( 'https-proxy-agent' ) ;
@@ -161,14 +162,16 @@ HttpsProxyAgent.prototype.callback = function connect(req, opts, fn) {
161
162
// that the node core `http` can parse and handle the error status code
162
163
cleanup ( ) ;
163
164
164
- // the original socket is closed, and a "fake socket" EventEmitter is
165
+ // the original socket is closed, and a new closed socket is
165
166
// returned instead, so that the proxy doesn't get the HTTP request
166
167
// written to it (which may contain `Authorization` headers or other
167
168
// sensitive data).
168
169
//
169
170
// See: https://hackerone.com/reports/541502
170
171
socket . destroy ( ) ;
171
- socket = new events . EventEmitter ( ) ;
172
+ socket = new net . Socket ( ) ;
173
+ socket . readable = true ;
174
+
172
175
173
176
// save a reference to the concat'd Buffer for the `onsocket` callback
174
177
buffers = buffered ;
@@ -182,15 +185,11 @@ HttpsProxyAgent.prototype.callback = function connect(req, opts, fn) {
182
185
183
186
function onsocket ( socket ) {
184
187
debug ( 'replaying proxy buffer for failed request' ) ;
188
+ assert ( socket . listenerCount ( 'data' ) > 0 ) ;
185
189
186
190
// replay the "buffers" Buffer onto the `socket`, since at this point
187
191
// the HTTP module machinery has been hooked up for the user
188
- if ( socket . listenerCount ( 'data' ) > 0 ) {
189
- socket . emit ( 'data' , buffers ) ;
190
- } else {
191
- // never?
192
- throw new Error ( 'should not happen...' ) ;
193
- }
192
+ socket . push ( buffers ) ;
194
193
195
194
// nullify the cached Buffer instance
196
195
buffers = null ;
0 commit comments