@@ -38,7 +38,7 @@ describe('lib/http-proxy.js', function() {
38
38
}
39
39
} ) . listen ( ports . proxy ) ;
40
40
41
- var req = https . request ( {
41
+ https . request ( {
42
42
host : 'localhost' ,
43
43
port : ports . proxy ,
44
44
path : '/' ,
@@ -56,10 +56,7 @@ describe('lib/http-proxy.js', function() {
56
56
proxy . _server . close ( ) ;
57
57
done ( ) ;
58
58
} )
59
- } ) ;
60
-
61
- req . on ( 'error' , function ( err ) { console . log ( 'Erroring' , err ) ; } ) ;
62
- req . end ( ) ;
59
+ } ) . end ( ) ;
63
60
} )
64
61
} ) ;
65
62
describe ( 'HTTP to HTTPS' , function ( ) {
@@ -102,6 +99,51 @@ describe('lib/http-proxy.js', function() {
102
99
} ) . end ( ) ;
103
100
} )
104
101
} )
102
+ describe ( 'HTTPS to HTTPS' , function ( ) {
103
+ it ( 'should proxy the request en send back the response' , function ( done ) {
104
+ var ports = { source : gen . port , proxy : gen . port } ;
105
+ var source = https . createServer ( {
106
+ key : fs . readFileSync ( path . join ( __dirname , 'fixtures' , 'agent2-key.pem' ) ) ,
107
+ cert : fs . readFileSync ( path . join ( __dirname , 'fixtures' , 'agent2-cert.pem' ) ) ,
108
+ } , function ( req , res ) {
109
+ expect ( req . method ) . to . eql ( 'GET' ) ;
110
+ expect ( req . headers . host . split ( ':' ) [ 1 ] ) . to . eql ( ports . proxy ) ;
111
+ res . writeHead ( 200 , { 'Content-Type' : 'text/plain' } ) ;
112
+ res . end ( 'Hello from ' + ports . source ) ;
113
+ } ) ;
114
+
115
+ source . listen ( ports . source ) ;
116
+
117
+ var proxy = httpProxy . createProxyServer ( {
118
+ target : 'https://127.0.0.1:' + ports . source ,
119
+ ssl : {
120
+ key : fs . readFileSync ( path . join ( __dirname , 'fixtures' , 'agent2-key.pem' ) ) ,
121
+ cert : fs . readFileSync ( path . join ( __dirname , 'fixtures' , 'agent2-cert.pem' ) ) ,
122
+ } ,
123
+ secure : false
124
+ } ) . listen ( ports . proxy ) ;
125
+
126
+ https . request ( {
127
+ host : 'localhost' ,
128
+ port : ports . proxy ,
129
+ path : '/' ,
130
+ method : 'GET' ,
131
+ rejectUnauthorized : false
132
+ } , function ( res ) {
133
+ expect ( res . statusCode ) . to . eql ( 200 ) ;
134
+
135
+ res . on ( 'data' , function ( data ) {
136
+ expect ( data . toString ( ) ) . to . eql ( 'Hello from ' + ports . source ) ;
137
+ } ) ;
138
+
139
+ res . on ( 'end' , function ( ) {
140
+ source . close ( ) ;
141
+ proxy . _server . close ( ) ;
142
+ done ( ) ;
143
+ } )
144
+ } ) . end ( ) ;
145
+ } )
146
+ } ) ;
105
147
describe ( 'HTTPS not allow SSL self signed' , function ( ) {
106
148
it ( 'should fail with error' , function ( done ) {
107
149
var ports = { source : gen . port , proxy : gen . port } ;
0 commit comments