@@ -8,9 +8,11 @@ var Duplex = require('stream').Duplex,
8
8
var ProxyStream = module . exports = function ProxyStream ( response , options ) {
9
9
Duplex . call ( this ) ;
10
10
11
- var self = this ,
12
- target = options . target ,
13
- source = options . source ;
11
+ var self = this ,
12
+ target = options . target ,
13
+ source = options . source ;
14
+
15
+ self . origRes = response ;
14
16
15
17
this . once ( 'pipe' , function ( req ) {
16
18
var protocol = target . https ? https : http ,
@@ -21,8 +23,13 @@ var ProxyStream = module.exports = function ProxyStream(response, options) {
21
23
if ( options . changeOrigin ) {
22
24
outgoing . headers . host = target . host + ':' + target . port ;
23
25
}
24
-
25
- self . request = protocol . request ( outgoing , function ( res ) {
26
+
27
+ self . request = protocol . request ( outgoing ) ;
28
+ self . request . end ( ) ;
29
+
30
+ self . request . on ( 'response' , function ( res ) {
31
+ console . log ( 'yarr yarr' ) ;
32
+ self . response = res ;
26
33
if ( req . httpVersion === '1.0' ) {
27
34
res . headers . connection = req . headers . connection || 'close' ;
28
35
}
@@ -56,7 +63,8 @@ var ProxyStream = module.exports = function ProxyStream(response, options) {
56
63
} ) ;
57
64
response . writeHead ( response . statusCode ) ;
58
65
} ) ;
59
-
66
+
67
+
60
68
/*
61
69
//
62
70
// Handle 'error' events from the `reverseProxy`. Setup timeout override if needed
@@ -110,15 +118,16 @@ var ProxyStream = module.exports = function ProxyStream(response, options) {
110
118
111
119
} ;
112
120
121
+ ProxyStream . prototype = Object . create (
122
+ Duplex . prototype , { constructor : { value : ProxyStream } }
123
+ ) ;
124
+
113
125
ProxyStream . prototype . _write = function ( chunk , encoding , callback ) {
114
126
this . request . write ( chunk , encoding , callback ) ;
115
127
} ;
116
128
117
129
ProxyStream . prototype . _read = function ( size ) {
118
- var chunk = self . request . read ( ) ;
119
- if ( chunk !== null ) {
120
- this . push ( chunk ) ;
121
- }
130
+ var chunk = this . response ? this . response . read ( size ) : '' ;
131
+ console . log ( chunk . toString ( ) ) ;
132
+ this . push ( chunk ) ;
122
133
} ;
123
-
124
- util . inherits ( ProxyStream , Duplex ) ;
0 commit comments