@@ -6,23 +6,23 @@ describe('lib/http-proxy/passes/web-outgoing.js', function () {
6
6
beforeEach ( function ( ) {
7
7
this . req = {
8
8
headers : {
9
- host : " ext-auto.com"
9
+ host : ' ext-auto.com'
10
10
}
11
11
} ;
12
12
this . proxyRes = {
13
13
statusCode : 301 ,
14
14
headers : {
15
- location : " http://backend.com/"
15
+ location : ' http://backend.com/'
16
16
}
17
17
} ;
18
18
this . options = {
19
- target : " http://backend.com"
19
+ target : ' http://backend.com'
20
20
} ;
21
21
} ) ;
22
22
23
23
context ( 'rewrites location host with hostRewrite' , function ( ) {
24
24
beforeEach ( function ( ) {
25
- this . options . hostRewrite = " ext-manual.com" ;
25
+ this . options . hostRewrite = ' ext-manual.com' ;
26
26
} ) ;
27
27
[ 201 , 301 , 302 , 307 , 308 ] . forEach ( function ( code ) {
28
28
it ( 'on ' + code , function ( ) {
@@ -52,14 +52,14 @@ describe('lib/http-proxy/passes/web-outgoing.js', function () {
52
52
53
53
it ( 'not when the redirected location does not match target host' , function ( ) {
54
54
this . proxyRes . statusCode = 302 ;
55
- this . proxyRes . headers . location = " http://some-other/" ;
55
+ this . proxyRes . headers . location = ' http://some-other/' ;
56
56
httpProxy . setRedirectHostRewrite ( this . req , { } , this . proxyRes , this . options ) ;
57
57
expect ( this . proxyRes . headers . location ) . to . eql ( 'http://some-other/' ) ;
58
58
} ) ;
59
59
60
60
it ( 'not when the redirected location does not match target port' , function ( ) {
61
61
this . proxyRes . statusCode = 302 ;
62
- this . proxyRes . headers . location = " http://backend.com:8080/" ;
62
+ this . proxyRes . headers . location = ' http://backend.com:8080/' ;
63
63
httpProxy . setRedirectHostRewrite ( this . req , { } , this . proxyRes , this . options ) ;
64
64
expect ( this . proxyRes . headers . location ) . to . eql ( 'http://backend.com:8080/' ) ;
65
65
} ) ;
@@ -91,14 +91,14 @@ describe('lib/http-proxy/passes/web-outgoing.js', function () {
91
91
92
92
it ( 'not when the redirected location does not match target host' , function ( ) {
93
93
this . proxyRes . statusCode = 302 ;
94
- this . proxyRes . headers . location = " http://some-other/" ;
94
+ this . proxyRes . headers . location = ' http://some-other/' ;
95
95
httpProxy . setRedirectHostRewrite ( this . req , { } , this . proxyRes , this . options ) ;
96
96
expect ( this . proxyRes . headers . location ) . to . eql ( 'http://some-other/' ) ;
97
97
} ) ;
98
98
99
99
it ( 'not when the redirected location does not match target port' , function ( ) {
100
100
this . proxyRes . statusCode = 302 ;
101
- this . proxyRes . headers . location = " http://backend.com:8080/" ;
101
+ this . proxyRes . headers . location = ' http://backend.com:8080/' ;
102
102
httpProxy . setRedirectHostRewrite ( this . req , { } , this . proxyRes , this . options ) ;
103
103
expect ( this . proxyRes . headers . location ) . to . eql ( 'http://backend.com:8080/' ) ;
104
104
} ) ;
@@ -129,13 +129,13 @@ describe('lib/http-proxy/passes/web-outgoing.js', function () {
129
129
} ) ;
130
130
131
131
it ( 'works together with hostRewrite' , function ( ) {
132
- this . options . hostRewrite = 'ext-manual.com'
132
+ this . options . hostRewrite = 'ext-manual.com' ;
133
133
httpProxy . setRedirectHostRewrite ( this . req , { } , this . proxyRes , this . options ) ;
134
134
expect ( this . proxyRes . headers . location ) . to . eql ( 'https://ext-manual.com/' ) ;
135
135
} ) ;
136
136
137
137
it ( 'works together with autoRewrite' , function ( ) {
138
- this . options . autoRewrite = true
138
+ this . options . autoRewrite = true ;
139
139
httpProxy . setRedirectHostRewrite ( this . req , { } , this . proxyRes , this . options ) ;
140
140
expect ( this . proxyRes . headers . location ) . to . eql ( 'https://ext-auto.com/' ) ;
141
141
} ) ;
@@ -199,31 +199,89 @@ describe('lib/http-proxy/passes/web-outgoing.js', function () {
199
199
writeHead : function ( n ) {
200
200
expect ( n ) . to . eql ( 200 ) ;
201
201
}
202
- }
202
+ } ;
203
203
204
204
httpProxy . writeStatusCode ( { } , res , { statusCode : 200 } ) ;
205
205
} ) ;
206
206
} ) ;
207
207
208
208
describe ( '#writeHeaders' , function ( ) {
209
- var proxyRes = {
210
- headers : {
211
- hey : 'hello' ,
212
- how : 'are you?'
213
- }
214
- } ;
209
+ beforeEach ( function ( ) {
210
+ this . proxyRes = {
211
+ headers : {
212
+ hey : 'hello' ,
213
+ how : 'are you?' ,
214
+ 'set-cookie' : 'hello; domain=my.domain; path=/'
215
+ }
216
+ } ;
217
+ this . res = {
218
+ setHeader : function ( k , v ) {
219
+ this . headers [ k ] = v ;
220
+ } ,
221
+ headers : { }
222
+ } ;
223
+ } ) ;
215
224
216
- var res = {
217
- setHeader : function ( k , v ) {
218
- this . headers [ k ] = v ;
219
- } ,
220
- headers : { }
221
- } ;
225
+ it ( 'writes headers' , function ( ) {
226
+ var options = { } ;
222
227
223
- httpProxy . writeHeaders ( { } , res , proxyRes ) ;
228
+ httpProxy . writeHeaders ( { } , this . res , this . proxyRes , options ) ;
229
+
230
+ expect ( this . res . headers . hey ) . to . eql ( 'hello' ) ;
231
+ expect ( this . res . headers . how ) . to . eql ( 'are you?' ) ;
232
+ } ) ;
224
233
225
- expect ( res . headers . hey ) . to . eql ( 'hello' ) ;
226
- expect ( res . headers . how ) . to . eql ( 'are you?' ) ;
234
+ it ( 'does not rewrite domain' , function ( ) {
235
+ var options = { } ;
236
+
237
+ httpProxy . writeHeaders ( { } , this . res , this . proxyRes , options ) ;
238
+
239
+ expect ( this . res . headers [ 'set-cookie' ] ) . to . eql ( 'hello; domain=my.domain; path=/' ) ;
240
+ } ) ;
241
+
242
+ it ( 'rewrites domain' , function ( ) {
243
+ var options = {
244
+ cookieDomainRewrite : 'my.new.domain'
245
+ } ;
246
+
247
+ httpProxy . writeHeaders ( { } , this . res , this . proxyRes , options ) ;
248
+
249
+ expect ( this . res . headers [ 'set-cookie' ] ) . to . eql ( 'hello; domain=my.new.domain; path=/' ) ;
250
+ } ) ;
251
+
252
+ it ( 'removes domain' , function ( ) {
253
+ var options = {
254
+ cookieDomainRewrite : ''
255
+ } ;
256
+
257
+ httpProxy . writeHeaders ( { } , this . res , this . proxyRes , options ) ;
258
+
259
+ expect ( this . res . headers [ 'set-cookie' ] ) . to . eql ( 'hello; path=/' ) ;
260
+ } ) ;
261
+
262
+ it ( 'rewrites headers with advanced configuration' , function ( ) {
263
+ var options = {
264
+ cookieDomainRewrite : {
265
+ '*' : '' ,
266
+ 'my.old.domain' : 'my.new.domain' ,
267
+ 'my.special.domain' : 'my.special.domain'
268
+ }
269
+ } ;
270
+ this . proxyRes . headers [ 'set-cookie' ] = [
271
+ 'hello-on-my.domain; domain=my.domain; path=/' ,
272
+ 'hello-on-my.old.domain; domain=my.old.domain; path=/' ,
273
+ 'hello-on-my.special.domain; domain=my.special.domain; path=/'
274
+ ] ;
275
+
276
+ httpProxy . writeHeaders ( { } , this . res , this . proxyRes , options ) ;
277
+
278
+ expect ( this . res . headers [ 'set-cookie' ] )
279
+ . to . contain ( 'hello-on-my.domain; path=/' ) ;
280
+ expect ( this . res . headers [ 'set-cookie' ] )
281
+ . to . contain ( 'hello-on-my.old.domain; domain=my.new.domain; path=/' ) ;
282
+ expect ( this . res . headers [ 'set-cookie' ] )
283
+ . to . contain ( 'hello-on-my.special.domain; domain=my.special.domain; path=/' ) ;
284
+ } ) ;
227
285
} ) ;
228
286
229
287
0 commit comments