1
- var httpProxy = require ( '../lib/http-proxy/passes/ws-incoming' ) ,
1
+ var wsPasses = require ( '../lib/http-proxy/passes/ws-incoming' ) ,
2
2
expect = require ( 'expect.js' ) ,
3
3
http = require ( 'http' ) ,
4
- httpProxyLib = require ( '../lib/http-proxy' ) ;
4
+ httpProxy = require ( '../lib/http-proxy' ) ;
5
5
6
6
describe ( 'lib/http-proxy/passes/ws-incoming.js' , function ( ) {
7
7
describe ( '#checkMethodAndHeader' , function ( ) {
@@ -17,7 +17,7 @@ describe('lib/http-proxy/passes/ws-incoming.js', function () {
17
17
destroyCalled = true ;
18
18
}
19
19
}
20
- returnValue = httpProxy . checkMethodAndHeader ( stubRequest , stubSocket ) ;
20
+ returnValue = wsPasses . checkMethodAndHeader ( stubRequest , stubSocket ) ;
21
21
expect ( returnValue ) . to . be ( true ) ;
22
22
expect ( destroyCalled ) . to . be ( true ) ;
23
23
} )
@@ -34,7 +34,7 @@ describe('lib/http-proxy/passes/ws-incoming.js', function () {
34
34
destroyCalled = true ;
35
35
}
36
36
}
37
- returnValue = httpProxy . checkMethodAndHeader ( stubRequest , stubSocket ) ;
37
+ returnValue = wsPasses . checkMethodAndHeader ( stubRequest , stubSocket ) ;
38
38
expect ( returnValue ) . to . be ( true ) ;
39
39
expect ( destroyCalled ) . to . be ( true ) ;
40
40
} )
@@ -53,7 +53,7 @@ describe('lib/http-proxy/passes/ws-incoming.js', function () {
53
53
destroyCalled = true ;
54
54
}
55
55
}
56
- returnValue = httpProxy . checkMethodAndHeader ( stubRequest , stubSocket ) ;
56
+ returnValue = wsPasses . checkMethodAndHeader ( stubRequest , stubSocket ) ;
57
57
expect ( returnValue ) . to . be ( true ) ;
58
58
expect ( destroyCalled ) . to . be ( true ) ;
59
59
} )
@@ -72,14 +72,13 @@ describe('lib/http-proxy/passes/ws-incoming.js', function () {
72
72
destroyCalled = true ;
73
73
}
74
74
}
75
- returnValue = httpProxy . checkMethodAndHeader ( stubRequest , stubSocket ) ;
75
+ returnValue = wsPasses . checkMethodAndHeader ( stubRequest , stubSocket ) ;
76
76
expect ( returnValue ) . to . be ( undefined ) ;
77
77
expect ( destroyCalled ) . to . be ( false ) ;
78
78
} )
79
79
80
-
81
80
it ( 'should detect a proxyWsReq event and modify headers' , function ( done ) {
82
- var proxy = httpProxyLib . createProxyServer ( {
81
+ var proxy = httpProxy . createProxyServer ( {
83
82
target : 'http://127.0.0.1:8080' ,
84
83
ws : true
85
84
} ) ;
@@ -95,18 +94,18 @@ describe('lib/http-proxy/passes/ws-incoming.js', function () {
95
94
var proxyServer = http . createServer ( requestHandler ) ;
96
95
97
96
proxyServer . on ( 'upgrade' , function ( req , res , head ) {
98
- proxy . ws ( req , res , head ) ;
97
+ proxy . ws ( req , res , head ) ;
99
98
} ) ;
100
99
101
100
var source = http . createServer ( function ( req , res ) {
102
- res . end ( ) ;
101
+ res . end ( ) ;
103
102
} ) ;
104
103
105
104
source . on ( 'upgrade' , function ( req , res , head ) {
106
- expect ( req . headers [ 'x-special-proxy-header' ] ) . to . eql ( 'foobar' ) ;
107
- source . close ( ) ;
108
- proxyServer . close ( ) ;
109
- done ( ) ;
105
+ expect ( req . headers [ 'x-special-proxy-header' ] ) . to . eql ( 'foobar' ) ;
106
+ source . close ( ) ;
107
+ proxyServer . close ( ) ;
108
+ done ( ) ;
110
109
} ) ;
111
110
112
111
source . on ( 'error' , function ( ) { } ) ;
@@ -122,11 +121,11 @@ describe('lib/http-proxy/passes/ws-incoming.js', function () {
122
121
method : 'GET' ,
123
122
path : '/' ,
124
123
headers : {
125
- 'upgrade' : 'websocket' ,
126
- 'connection' : 'Upgrade' ,
127
- 'sec-websocket-key' : 'dGhlIHNhbXBsZSBub25jZQ==' ,
128
- 'sec-websocket-protocol' : 'chat, superchat' ,
129
- 'sec-websocket-version' : 13
124
+ 'upgrade' : 'websocket' ,
125
+ 'connection' : 'Upgrade' ,
126
+ 'sec-websocket-key' : 'dGhlIHNhbXBsZSBub25jZQ==' ,
127
+ 'sec-websocket-protocol' : 'chat, superchat' ,
128
+ 'sec-websocket-version' : 13
130
129
}
131
130
} , function ( ) { } ) ;
132
131
request . on ( 'error' , function ( ) { } ) ;
@@ -136,7 +135,7 @@ describe('lib/http-proxy/passes/ws-incoming.js', function () {
136
135
137
136
describe ( '#XHeaders' , function ( ) {
138
137
it ( 'return if no forward request' , function ( ) {
139
- var returnValue = httpProxy . XHeaders ( { } , { } , { } ) ;
138
+ var returnValue = wsPasses . XHeaders ( { } , { } , { } ) ;
140
139
expect ( returnValue ) . to . be ( undefined ) ;
141
140
} ) ;
142
141
@@ -149,8 +148,8 @@ describe('lib/http-proxy/passes/ws-incoming.js', function () {
149
148
headers : {
150
149
host : '192.168.1.2:8080'
151
150
}
152
- }
153
- httpProxy . XHeaders ( stubRequest , { } , { xfwd : true } ) ;
151
+ } ;
152
+ wsPasses . XHeaders ( stubRequest , { } , { xfwd : true } ) ;
154
153
expect ( stubRequest . headers [ 'x-forwarded-for' ] ) . to . be ( '192.168.1.2' ) ;
155
154
expect ( stubRequest . headers [ 'x-forwarded-port' ] ) . to . be ( '8080' ) ;
156
155
expect ( stubRequest . headers [ 'x-forwarded-proto' ] ) . to . be ( 'ws' ) ;
@@ -169,7 +168,7 @@ describe('lib/http-proxy/passes/ws-incoming.js', function () {
169
168
host : '192.168.1.3:8181'
170
169
}
171
170
} ;
172
- httpProxy . XHeaders ( stubRequest , { } , { xfwd : true } ) ;
171
+ wsPasses . XHeaders ( stubRequest , { } , { xfwd : true } ) ;
173
172
expect ( stubRequest . headers [ 'x-forwarded-for' ] ) . to . be ( '192.168.1.3' ) ;
174
173
expect ( stubRequest . headers [ 'x-forwarded-port' ] ) . to . be ( '8181' ) ;
175
174
expect ( stubRequest . headers [ 'x-forwarded-proto' ] ) . to . be ( 'wss' ) ;
0 commit comments