1
1
var httpProxy = require ( '../lib/http-proxy' ) ,
2
2
expect = require ( 'expect.js' ) ,
3
3
http = require ( 'http' ) ,
4
- ws = require ( 'ws' )
4
+ net = require ( 'net' ) ,
5
+ ws = require ( 'ws' ) ,
5
6
io = require ( 'socket.io' ) ,
6
7
SSE = require ( 'sse' ) ,
7
8
ioClient = require ( 'socket.io-client' ) ;
@@ -17,7 +18,6 @@ Object.defineProperty(gen, 'port', {
17
18
}
18
19
} ) ;
19
20
20
-
21
21
describe ( 'lib/http-proxy.js' , function ( ) {
22
22
describe ( '#createProxyServer' , function ( ) {
23
23
it . skip ( 'should throw without options' , function ( ) {
@@ -223,11 +223,54 @@ describe('lib/http-proxy.js', function() {
223
223
} ) ;
224
224
225
225
testReq . end ( ) ;
226
+ } ) ;
227
+ } ) ;
228
+
229
+ describe ( '#createProxyServer with xfwd option' , function ( ) {
230
+ it ( 'should not throw on empty http host header' , function ( done ) {
231
+ var ports = { source : gen . port , proxy : gen . port } ;
232
+ var proxy = httpProxy . createProxyServer ( {
233
+ forward : 'http://127.0.0.1:' + ports . source ,
234
+ xfwd : true
235
+ } ) . listen ( ports . proxy ) ;
236
+
237
+ var source = http . createServer ( function ( req , res ) {
238
+ expect ( req . method ) . to . eql ( 'GET' ) ;
239
+ expect ( req . headers . host . split ( ':' ) [ 1 ] ) . to . eql ( ports . source ) ;
240
+ source . close ( ) ;
241
+ proxy . close ( ) ;
242
+ done ( ) ;
243
+ } ) ;
244
+
245
+ source . listen ( ports . source ) ;
246
+
247
+ var socket = net . connect ( { port : ports . proxy } , function ( )
248
+ {
249
+ socket . write ( 'GET / HTTP/1.0\r\n\r\n' ) ;
250
+ } ) ;
251
+
252
+ // handle errors
253
+ socket . on ( 'error' , function ( )
254
+ {
255
+ expect . fail ( 'Unexpected socket error' ) ;
256
+ } ) ;
257
+
258
+ socket . on ( 'data' , function ( data )
259
+ {
260
+ socket . end ( ) ;
261
+ } ) ;
262
+
263
+ socket . on ( 'end' , function ( )
264
+ {
265
+ expect ( 'Socket to finish' ) . to . be . ok ( ) ;
266
+ } ) ;
267
+
268
+ // http.request('http://127.0.0.1:' + ports.proxy, function() {}).end();
226
269
} )
227
- } )
270
+ } ) ;
228
271
229
272
// describe('#createProxyServer using the web-incoming passes', function () {
230
- // it('should emit events correclty ', function(done) {
273
+ // it('should emit events correctly ', function(done) {
231
274
// var proxy = httpProxy.createProxyServer({
232
275
// target: 'http://127.0.0.1:8080'
233
276
// }),
@@ -451,7 +494,7 @@ describe('lib/http-proxy.js', function() {
451
494
proxyServer = proxy . listen ( ports . proxy ) ,
452
495
destiny = new ws . Server ( { port : ports . source } , function ( ) {
453
496
var key = new Buffer ( Math . random ( ) . toString ( ) ) . toString ( 'base64' ) ;
454
-
497
+
455
498
var requestOptions = {
456
499
port : ports . proxy ,
457
500
host : '127.0.0.1' ,
@@ -465,15 +508,15 @@ describe('lib/http-proxy.js', function() {
465
508
} ;
466
509
467
510
var req = http . request ( requestOptions ) ;
468
-
511
+
469
512
req . on ( 'upgrade' , function ( res , socket , upgradeHead ) {
470
513
expect ( res . headers [ 'set-cookie' ] . length ) . to . be ( 2 ) ;
471
514
done ( ) ;
472
515
} ) ;
473
-
516
+
474
517
req . end ( ) ;
475
518
} ) ;
476
-
519
+
477
520
destiny . on ( 'headers' , function ( headers ) {
478
521
headers . push ( 'Set-Cookie: test1=test1' ) ;
479
522
headers . push ( 'Set-Cookie: test2=test2' ) ;
@@ -554,7 +597,7 @@ describe('lib/http-proxy.js', function() {
554
597
} ) ;
555
598
} ) ;
556
599
} ) ;
557
-
600
+
558
601
it ( 'should forward continuation frames with big payload (including on node 4.x)' , function ( done ) {
559
602
var payload = Array ( 65530 ) . join ( '0' ) ;
560
603
var ports = { source : gen . port , proxy : gen . port } ;
0 commit comments