@@ -152,26 +152,35 @@ exports.httputil = function (cgi, envReady) {
152152 var server = http . createServer ( cgi ) ;
153153 server . listen ( port , hostname ) ;
154154
155- var client = http . createClient ( port , hostname ) ;
156- client . fetch = function ( method , path , headers , respReady ) {
157- var request = this . request ( method , path , headers ) ;
158- request . end ( ) ;
159- request . on ( 'response' , function ( response ) {
160- response . setEncoding ( 'utf8' ) ;
161- response . on ( 'data' , function ( chunk ) {
162- if ( response . body ) {
163- response . body += chunk ;
164- } else {
165- response . body = chunk ;
166- }
155+ var agent = new http . Agent ( { host : hostname , port : port , maxSockets : 1 } ) ;
156+ var client = {
157+ fetch : function ( method , path , headers , respReady ) {
158+ var request = http . request ( {
159+ host : hostname ,
160+ port : port ,
161+ agent : agent ,
162+ method : method ,
163+ path : path ,
164+ headers : headers
167165 } ) ;
168- response . on ( 'end' , function ( ) {
169- if ( response . headers [ 'content-type' ] === 'application/json' ) {
170- response . bodyAsObject = JSON . parse ( response . body ) ;
171- }
172- respReady ( response ) ;
166+ request . end ( ) ;
167+ request . on ( 'response' , function ( response ) {
168+ response . setEncoding ( 'utf8' ) ;
169+ response . on ( 'data' , function ( chunk ) {
170+ if ( response . body ) {
171+ response . body += chunk ;
172+ } else {
173+ response . body = chunk ;
174+ }
175+ } ) ;
176+ response . on ( 'end' , function ( ) {
177+ if ( response . headers [ 'content-type' ] === 'application/json' ) {
178+ response . bodyAsObject = JSON . parse ( response . body ) ;
179+ }
180+ respReady ( response ) ;
181+ } ) ;
173182 } ) ;
174- } ) ;
183+ }
175184 } ;
176185
177186 process . nextTick ( function ( ) {
0 commit comments