@@ -145,78 +145,83 @@ HttpProxy.prototype = {
145
145
self . body = '' ;
146
146
147
147
// Open new HTTP request to internal resource with will act as a reverse proxy pass
148
- var p = manager . getPool ( port , server ) ;
149
- sys . puts ( 'Current pool count for ' + req . headers . host + ":" + port + ' ' + p . clients . length + ', Busy: ' + p . getBusy ( ) + ', Free: ' + p . getFree ( ) ) ;
148
+ // var p = manager.getPool(port, server);
149
+ // sys.puts('Current pool count for ' + req.headers.host + ":" + port + ' ' + p.clients.length + ', Busy: ' + p.getBusy() + ', Free: ' + p.getFree());
150
150
151
- p . on ( 'error' , function ( err ) {
151
+ // p.on('error', function (err) {
152
152
// Remark: We should probably do something here
153
153
// but this is a hot-fix because I don't think 'pool'
154
154
// should be emitting this event.
155
- } ) ;
155
+ //});
156
+
157
+ var client = http . createClient ( port , server ) ;
158
+ var reverse_proxy = client . request ( req . method , req . url , req . headers ) ;
156
159
157
- p . request ( req . method , req . url , req . headers , function ( reverse_proxy ) {
158
- // Create an error handler so we can use it temporarily
159
- var error = function ( err ) {
160
- res . writeHead ( 500 , { 'Content-Type' : 'text/plain' } ) ;
160
+ //p.request(req.method, req.url, req.headers, function (reverse_proxy) {
161
161
162
- if ( req . method !== 'HEAD' ) {
163
- res . write ( 'An error has occurred: ' + JSON . stringify ( err ) ) ;
164
- }
165
-
166
- // Response end may never come so removeListener here
167
- reverse_proxy . removeListener ( 'error' , error ) ;
168
- res . end ( ) ;
169
- } ;
162
+ // Create an error handler so we can use it temporarily
163
+ var error = function ( err ) {
164
+ res . writeHead ( 500 , { 'Content-Type' : 'text/plain' } ) ;
170
165
171
- // Add a listener for the connection timeout event
172
- reverse_proxy . addListener ( 'error' , error ) ;
166
+ if ( req . method !== 'HEAD' ) {
167
+ res . write ( 'An error has occurred: ' + JSON . stringify ( err ) ) ;
168
+ }
169
+
170
+ // Response end may never come so removeListener here
171
+ reverse_proxy . removeListener ( 'error' , error ) ;
172
+ res . end ( ) ;
173
+ } ;
173
174
174
- // Add a listener for the reverse_proxy response event
175
- reverse_proxy . addListener ( 'response' , function ( response ) {
176
- if ( response . headers . connection ) {
177
- if ( req . headers . connection ) response . headers . connection = req . headers . connection ;
178
- else response . headers . connection = 'close' ;
179
- }
175
+ // Add a listener for the connection timeout event
176
+ reverse_proxy . addListener ( 'error' , error ) ;
180
177
181
- // Set the response headers of the client response
182
- res . writeHead ( response . statusCode , response . headers ) ;
178
+ // Add a listener for the reverse_proxy response event
179
+ reverse_proxy . addListener ( 'response' , function ( response ) {
180
+ if ( response . headers . connection ) {
181
+ if ( req . headers . connection ) response . headers . connection = req . headers . connection ;
182
+ else response . headers . connection = 'close' ;
183
+ }
183
184
184
- // Status code = 304
185
- // No 'data' event and no 'end'
186
- if ( response . statusCode === 304 ) {
187
- res . end ( ) ;
188
- return ;
189
- }
185
+ // Set the response headers of the client response
186
+ res . writeHead ( response . statusCode , response . headers ) ;
190
187
191
- // Add event handler for the proxied response in chunks
192
- response . addListener ( 'data' , function ( chunk ) {
193
- if ( req . method !== 'HEAD' ) {
194
- res . write ( chunk , 'binary' ) ;
195
- self . body += chunk ;
196
- }
197
- } ) ;
188
+ // Status code = 304
189
+ // No 'data' event and no 'end'
190
+ if ( response . statusCode === 304 ) {
191
+ res . end ( ) ;
192
+ return ;
193
+ }
198
194
199
- // Add event listener for end of proxied response
200
- response . addListener ( 'end' , function ( ) {
201
- // Remark: Emit the end event for testability
202
- self . emitter . emit ( 'proxy' , null , self . body ) ;
203
- reverse_proxy . removeListener ( 'error' , error ) ;
204
- res . end ( ) ;
205
- } ) ;
195
+ // Add event handler for the proxied response in chunks
196
+ response . addListener ( 'data' , function ( chunk ) {
197
+ if ( req . method !== 'HEAD' ) {
198
+ res . write ( chunk , 'binary' ) ;
199
+ self . body += chunk ;
200
+ }
206
201
} ) ;
207
202
208
- // Chunk the client request body as chunks from the proxied request come in
209
- req . addListener ( 'data' , function ( chunk ) {
210
- reverse_proxy . write ( chunk , 'binary' ) ;
211
- } )
212
-
213
- // At the end of the client request, we are going to stop the proxied request
214
- req . addListener ( 'end' , function ( ) {
215
- reverse_proxy . end ( ) ;
203
+ // Add event listener for end of proxied response
204
+ response . addListener ( 'end' , function ( ) {
205
+ // Remark: Emit the end event for testability
206
+ self . emitter . emit ( 'proxy' , null , self . body ) ;
207
+ reverse_proxy . removeListener ( 'error' , error ) ;
208
+ res . end ( ) ;
216
209
} ) ;
210
+ } ) ;
217
211
218
- self . unwatch ( req ) ;
212
+ // Chunk the client request body as chunks from the proxied request come in
213
+ req . addListener ( 'data' , function ( chunk ) {
214
+ reverse_proxy . write ( chunk , 'binary' ) ;
215
+ } )
216
+
217
+ // At the end of the client request, we are going to stop the proxied request
218
+ req . addListener ( 'end' , function ( ) {
219
+ reverse_proxy . end ( ) ;
219
220
} ) ;
221
+
222
+ self . unwatch ( req ) ;
223
+
224
+ //});
220
225
} ,
221
226
222
227
proxyWebSocketRequest : function ( port , server , host ) {
0 commit comments