@@ -22,7 +22,6 @@ describe('lib/http-proxy.js', function() {
22
22
it ( 'should proxy the request en send back the response' , function ( done ) {
23
23
var ports = { source : gen . port , proxy : gen . port } ;
24
24
var source = http . createServer ( function ( req , res ) {
25
- console . log ( 'Request:' , req . headers ) ;
26
25
expect ( req . method ) . to . eql ( 'GET' ) ;
27
26
expect ( req . headers . host . split ( ':' ) [ 1 ] ) . to . eql ( ports . proxy ) ;
28
27
res . writeHead ( 200 , { 'Content-Type' : 'text/plain' } ) ;
@@ -32,7 +31,7 @@ describe('lib/http-proxy.js', function() {
32
31
source . listen ( ports . source ) ;
33
32
34
33
var proxy = httpProxy . createProxyServer ( {
35
- forward : 'http://127.0.0.1:' + ports . source ,
34
+ target : 'http://127.0.0.1:' + ports . source ,
36
35
ssl : {
37
36
key : fs . readFileSync ( path . join ( __dirname , 'fixtures' , 'agent2-key.pem' ) ) ,
38
37
cert : fs . readFileSync ( path . join ( __dirname , 'fixtures' , 'agent2-cert.pem' ) ) ,
@@ -44,22 +43,62 @@ describe('lib/http-proxy.js', function() {
44
43
port : ports . proxy ,
45
44
path : '/' ,
46
45
method : 'GET' ,
47
- localAddress : '127.0.0.1' ,
48
46
rejectUnauthorized : false
49
47
} , function ( res ) {
50
- console . log ( res ) ;
51
- res . on ( 'data' , function ( ch ) {
52
- console . log ( 'Chunks' , ch )
48
+ expect ( res . statusCode ) . to . eql ( 200 ) ;
49
+
50
+ res . on ( 'data' , function ( data ) {
51
+ expect ( data . toString ( ) ) . to . eql ( 'Hello from ' + ports . source ) ;
52
+ } ) ;
53
+
54
+ res . on ( 'end' , function ( ) {
55
+ source . close ( ) ;
56
+ proxy . _server . close ( ) ;
57
+ done ( ) ;
53
58
} )
54
- console . log ( 'Response:' , res . statusCode ) ;
55
- source . close ( ) ;
56
- proxy . _server . close ( ) ;
57
- done ( ) ;
58
59
} ) ;
59
60
60
61
req . on ( 'error' , function ( err ) { console . log ( 'Erroring' , err ) ; } ) ;
61
62
req . end ( ) ;
62
63
} )
63
- } )
64
+ } ) ;
65
+ describe ( 'HTTP to HTTPS' , function ( ) {
66
+ it ( 'should proxy the request en send back the response' , function ( done ) {
67
+ var ports = { source : gen . port , proxy : gen . port } ;
68
+ var source = https . createServer ( {
69
+ key : fs . readFileSync ( path . join ( __dirname , 'fixtures' , 'agent2-key.pem' ) ) ,
70
+ cert : fs . readFileSync ( path . join ( __dirname , 'fixtures' , 'agent2-cert.pem' ) ) ,
71
+ } , function ( req , res ) {
72
+ expect ( req . method ) . to . eql ( 'GET' ) ;
73
+ expect ( req . headers . host . split ( ':' ) [ 1 ] ) . to . eql ( ports . proxy ) ;
74
+ res . writeHead ( 200 , { 'Content-Type' : 'text/plain' } ) ;
75
+ res . end ( 'Hello from ' + ports . source ) ;
76
+ } ) ;
77
+
78
+ source . listen ( ports . source ) ;
79
+
80
+ var proxy = httpProxy . createProxyServer ( {
81
+ target : 'https://127.0.0.1:' + ports . source ,
82
+ } ) . listen ( ports . proxy ) ;
83
+
84
+ http . request ( {
85
+ hostname : '127.0.0.1' ,
86
+ port : ports . proxy ,
87
+ method : 'GET'
88
+ } , function ( res ) {
89
+ expect ( res . statusCode ) . to . eql ( 200 ) ;
90
+
91
+ res . on ( 'data' , function ( data ) {
92
+ expect ( data . toString ( ) ) . to . eql ( 'Hello from ' + ports . source ) ;
93
+ } ) ;
94
+
95
+ res . on ( 'end' , function ( ) {
96
+ source . close ( ) ;
97
+ proxy . _server . close ( ) ;
98
+ done ( ) ;
99
+ } ) ;
100
+ } ) . end ( ) ;
101
+ } )
102
+ } )
64
103
} ) ;
65
104
} ) ;
0 commit comments