@@ -233,12 +233,18 @@ describe('lib/http-proxy/passes/web-outgoing.js', function () {
233
233
headers : {
234
234
hey : 'hello' ,
235
235
how : 'are you?' ,
236
- 'set-cookie' : 'hello; domain=my.domain; path=/'
237
- } ,
236
+ 'set-cookie' : [
237
+ 'hello; domain=my.domain; path=/' ,
238
+ 'there; domain=my.domain; path=/'
239
+ ]
240
+ }
241
+ } ;
242
+ this . rawProxyRes = {
238
243
rawHeaders : [
239
244
'Hey' , 'hello' ,
240
245
'How' , 'are you?' ,
241
- 'Set-Cookie' , 'hello; domain=my.domain; path=/'
246
+ 'Set-Cookie' , 'hello; domain=my.domain; path=/' ,
247
+ 'Set-Cookie' , 'there; domain=my.domain; path=/'
242
248
]
243
249
} ;
244
250
this . res = {
@@ -253,19 +259,35 @@ describe('lib/http-proxy/passes/web-outgoing.js', function () {
253
259
254
260
it ( 'writes headers' , function ( ) {
255
261
var options = { } ;
256
-
257
262
httpProxy . writeHeaders ( { } , this . res , this . proxyRes , options ) ;
258
263
259
264
expect ( this . res . headers . hey ) . to . eql ( 'hello' ) ;
260
265
expect ( this . res . headers . how ) . to . eql ( 'are you?' ) ;
266
+
267
+ expect ( this . res . headers ) . to . have . key ( 'set-cookie' ) ;
268
+ expect ( this . res . headers [ 'set-cookie' ] ) . to . be . an ( Array ) ;
269
+ expect ( this . res . headers [ 'set-cookie' ] ) . to . have . length ( 2 ) ;
270
+ } ) ;
271
+
272
+ it ( 'writes raw headers' , function ( ) {
273
+ var options = { } ;
274
+ httpProxy . writeHeaders ( { } , this . res , this . rawProxyRes , options ) ;
275
+
276
+ expect ( this . res . headers . hey ) . to . eql ( 'hello' ) ;
277
+ expect ( this . res . headers . how ) . to . eql ( 'are you?' ) ;
278
+
279
+ expect ( this . res . headers ) . to . have . key ( 'set-cookie' ) ;
280
+ expect ( this . res . headers [ 'set-cookie' ] ) . to . be . an ( Array ) ;
281
+ expect ( this . res . headers [ 'set-cookie' ] ) . to . have . length ( 2 ) ;
261
282
} ) ;
262
283
263
284
it ( 'does not rewrite domain' , function ( ) {
264
285
var options = { } ;
265
286
266
287
httpProxy . writeHeaders ( { } , this . res , this . proxyRes , options ) ;
267
288
268
- expect ( this . res . headers [ 'set-cookie' ] ) . to . eql ( 'hello; domain=my.domain; path=/' ) ;
289
+ expect ( this . res . headers [ 'set-cookie' ] )
290
+ . to . contain ( 'hello; domain=my.domain; path=/' ) ;
269
291
} ) ;
270
292
271
293
it ( 'rewrites domain' , function ( ) {
@@ -275,7 +297,8 @@ describe('lib/http-proxy/passes/web-outgoing.js', function () {
275
297
276
298
httpProxy . writeHeaders ( { } , this . res , this . proxyRes , options ) ;
277
299
278
- expect ( this . res . headers [ 'set-cookie' ] ) . to . eql ( 'hello; domain=my.new.domain; path=/' ) ;
300
+ expect ( this . res . headers [ 'set-cookie' ] )
301
+ . to . contain ( 'hello; domain=my.new.domain; path=/' ) ;
279
302
} ) ;
280
303
281
304
it ( 'removes domain' , function ( ) {
@@ -285,7 +308,8 @@ describe('lib/http-proxy/passes/web-outgoing.js', function () {
285
308
286
309
httpProxy . writeHeaders ( { } , this . res , this . proxyRes , options ) ;
287
310
288
- expect ( this . res . headers [ 'set-cookie' ] ) . to . eql ( 'hello; path=/' ) ;
311
+ expect ( this . res . headers [ 'set-cookie' ] )
312
+ . to . contain ( 'hello; path=/' ) ;
289
313
} ) ;
290
314
291
315
it ( 'rewrites headers with advanced configuration' , function ( ) {
@@ -301,14 +325,33 @@ describe('lib/http-proxy/passes/web-outgoing.js', function () {
301
325
'hello-on-my.old.domain; domain=my.old.domain; path=/' ,
302
326
'hello-on-my.special.domain; domain=my.special.domain; path=/'
303
327
] ;
304
- var setCookieValueIndex = this . proxyRes . rawHeaders . indexOf ( 'Set-Cookie' ) + 1 ;
305
- this . proxyRes . rawHeaders [ setCookieValueIndex ] = [
328
+ httpProxy . writeHeaders ( { } , this . res , this . proxyRes , options ) ;
329
+
330
+ expect ( this . res . headers [ 'set-cookie' ] )
331
+ . to . contain ( 'hello-on-my.domain; path=/' ) ;
332
+ expect ( this . res . headers [ 'set-cookie' ] )
333
+ . to . contain ( 'hello-on-my.old.domain; domain=my.new.domain; path=/' ) ;
334
+ expect ( this . res . headers [ 'set-cookie' ] )
335
+ . to . contain ( 'hello-on-my.special.domain; domain=my.special.domain; path=/' ) ;
336
+ } ) ;
337
+
338
+ it ( 'rewrites raw headers with advanced configuration' , function ( ) {
339
+ var options = {
340
+ cookieDomainRewrite : {
341
+ '*' : '' ,
342
+ 'my.old.domain' : 'my.new.domain' ,
343
+ 'my.special.domain' : 'my.special.domain'
344
+ }
345
+ } ;
346
+ this . rawProxyRes . rawHeaders = this . rawProxyRes . rawHeaders . concat ( [
347
+ 'Set-Cookie' ,
306
348
'hello-on-my.domain; domain=my.domain; path=/' ,
349
+ 'Set-Cookie' ,
307
350
'hello-on-my.old.domain; domain=my.old.domain; path=/' ,
351
+ 'Set-Cookie' ,
308
352
'hello-on-my.special.domain; domain=my.special.domain; path=/'
309
- ] ;
310
-
311
- httpProxy . writeHeaders ( { } , this . res , this . proxyRes , options ) ;
353
+ ] ) ;
354
+ httpProxy . writeHeaders ( { } , this . res , this . rawProxyRes , options ) ;
312
355
313
356
expect ( this . res . headers [ 'set-cookie' ] )
314
357
. to . contain ( 'hello-on-my.domain; path=/' ) ;
0 commit comments