@@ -172,5 +172,51 @@ describe('lib/http-proxy.js', function() {
172
172
} ) . end ( ) ;
173
173
} )
174
174
} )
175
+ describe ( 'HTTPS to HTTP using own server' , function ( ) {
176
+ it ( 'should proxy the request en send back the response' , function ( done ) {
177
+ var ports = { source : gen . port , proxy : gen . port } ;
178
+ var source = http . createServer ( function ( req , res ) {
179
+ expect ( req . method ) . to . eql ( 'GET' ) ;
180
+ expect ( req . headers . host . split ( ':' ) [ 1 ] ) . to . eql ( ports . proxy ) ;
181
+ res . writeHead ( 200 , { 'Content-Type' : 'text/plain' } ) ;
182
+ res . end ( 'Hello from ' + ports . source ) ;
183
+ } ) ;
184
+
185
+ source . listen ( ports . source ) ;
186
+
187
+ var proxy = httpProxy . createServer ( {
188
+ agent : new http . Agent ( { maxSockets : 2 } )
189
+ } ) ;
190
+
191
+ var ownServer = https . createServer ( {
192
+ key : fs . readFileSync ( path . join ( __dirname , 'fixtures' , 'agent2-key.pem' ) ) ,
193
+ cert : fs . readFileSync ( path . join ( __dirname , 'fixtures' , 'agent2-cert.pem' ) ) ,
194
+ } , function ( req , res ) {
195
+ proxy . web ( req , res , {
196
+ target : 'http://127.0.0.1:' + ports . source
197
+ } )
198
+ } ) . listen ( ports . proxy ) ;
199
+
200
+ https . request ( {
201
+ host : 'localhost' ,
202
+ port : ports . proxy ,
203
+ path : '/' ,
204
+ method : 'GET' ,
205
+ rejectUnauthorized : false
206
+ } , function ( res ) {
207
+ expect ( res . statusCode ) . to . eql ( 200 ) ;
208
+
209
+ res . on ( 'data' , function ( data ) {
210
+ expect ( data . toString ( ) ) . to . eql ( 'Hello from ' + ports . source ) ;
211
+ } ) ;
212
+
213
+ res . on ( 'end' , function ( ) {
214
+ source . close ( ) ;
215
+ ownServer . close ( ) ;
216
+ done ( ) ;
217
+ } )
218
+ } ) . end ( ) ;
219
+ } )
220
+ } )
175
221
} ) ;
176
222
} ) ;
0 commit comments