@@ -2,6 +2,58 @@ var httpProxy = require('../lib/http-proxy/passes/web-outgoing'),
2
2
expect = require ( 'expect.js' ) ;
3
3
4
4
describe ( 'lib/http-proxy/passes/web-outgoing.js' , function ( ) {
5
+ describe ( '#setRedirectHostRewrite' , function ( ) {
6
+ context ( 'rewrites location host to option' , function ( ) {
7
+ beforeEach ( function ( ) {
8
+ this . proxyRes = {
9
+ statusCode : 301 ,
10
+ headers : {
11
+ location : "http://f.com/"
12
+ }
13
+ } ;
14
+
15
+ this . options = {
16
+ hostRewrite : "x.com"
17
+ } ;
18
+ } ) ;
19
+
20
+ it ( 'on 301' , function ( ) {
21
+ this . proxyRes . statusCode = 301 ;
22
+ httpProxy . setRedirectHostRewrite ( { } , { } , this . proxyRes , this . options ) ;
23
+ expect ( this . proxyRes . headers . location ) . to . eql ( 'http://' + this . options . hostRewrite + '/' ) ;
24
+ } ) ;
25
+
26
+ it ( 'on 302' , function ( ) {
27
+ this . proxyRes . statusCode = 302 ;
28
+ httpProxy . setRedirectHostRewrite ( { } , { } , this . proxyRes , this . options ) ;
29
+ expect ( this . proxyRes . headers . location ) . to . eql ( 'http://' + this . options . hostRewrite + '/' ) ;
30
+ } ) ;
31
+
32
+ it ( 'on 307' , function ( ) {
33
+ this . proxyRes . statusCode = 307 ;
34
+ httpProxy . setRedirectHostRewrite ( { } , { } , this . proxyRes , this . options ) ;
35
+ expect ( this . proxyRes . headers . location ) . to . eql ( 'http://' + this . options . hostRewrite + '/' ) ;
36
+ } ) ;
37
+
38
+ it ( 'on 308' , function ( ) {
39
+ this . proxyRes . statusCode = 308 ;
40
+ httpProxy . setRedirectHostRewrite ( { } , { } , this . proxyRes , this . options ) ;
41
+ expect ( this . proxyRes . headers . location ) . to . eql ( 'http://' + this . options . hostRewrite + '/' ) ;
42
+ } ) ;
43
+
44
+ it ( 'not on 200' , function ( ) {
45
+ this . proxyRes . statusCode = 200 ;
46
+ httpProxy . setRedirectHostRewrite ( { } , { } , this . proxyRes , this . options ) ;
47
+ expect ( this . proxyRes . headers . location ) . to . eql ( 'http://f.com/' ) ;
48
+ } ) ;
49
+
50
+ it ( 'not when hostRewrite is unset' , function ( ) {
51
+ httpProxy . setRedirectHostRewrite ( { } , { } , this . proxyRes , { } ) ;
52
+ expect ( this . proxyRes . headers . location ) . to . eql ( 'http://f.com/' ) ;
53
+ } ) ;
54
+ } ) ;
55
+ } ) ;
56
+
5
57
describe ( '#setConnection' , function ( ) {
6
58
it ( 'set the right connection with 1.0 - `close`' , function ( ) {
7
59
var proxyRes = { headers : { } } ;
0 commit comments