@@ -6,113 +6,110 @@ describe('lib/http-proxy/passes/web-outgoing.js', function () {
6
6
beforeEach ( function ( ) {
7
7
this . req = {
8
8
headers : {
9
- host : "x2 .com"
9
+ host : "ext-auto .com"
10
10
}
11
11
} ;
12
12
this . proxyRes = {
13
13
statusCode : 301 ,
14
14
headers : {
15
- location : "http://f .com/"
15
+ location : "http://backend .com/"
16
16
}
17
17
} ;
18
+ this . options = {
19
+ target : "http://backend.com"
20
+ } ;
18
21
} ) ;
19
22
20
23
context ( 'rewrites location host with hostRewrite' , function ( ) {
21
24
beforeEach ( function ( ) {
22
- this . options = {
23
- hostRewrite : "x.com"
24
- } ;
25
+ this . options . hostRewrite = "ext-manual.com" ;
25
26
} ) ;
26
27
[ 301 , 302 , 307 , 308 ] . forEach ( function ( code ) {
27
28
it ( 'on ' + code , function ( ) {
28
29
this . proxyRes . statusCode = code ;
29
30
httpProxy . setRedirectHostRewrite ( this . req , { } , this . proxyRes , this . options ) ;
30
- expect ( this . proxyRes . headers . location ) . to . eql ( 'http://' + this . options . hostRewrite + ' /') ;
31
+ expect ( this . proxyRes . headers . location ) . to . eql ( 'http://ext-manual.com /' ) ;
31
32
} ) ;
32
33
} ) ;
33
34
34
35
it ( 'not on 200' , function ( ) {
35
36
this . proxyRes . statusCode = 200 ;
36
37
httpProxy . setRedirectHostRewrite ( this . req , { } , this . proxyRes , this . options ) ;
37
- expect ( this . proxyRes . headers . location ) . to . eql ( 'http://f .com/' ) ;
38
+ expect ( this . proxyRes . headers . location ) . to . eql ( 'http://backend .com/' ) ;
38
39
} ) ;
39
40
40
41
it ( 'not when hostRewrite is unset' , function ( ) {
41
42
delete this . options . hostRewrite ;
42
43
httpProxy . setRedirectHostRewrite ( this . req , { } , this . proxyRes , this . options ) ;
43
- expect ( this . proxyRes . headers . location ) . to . eql ( 'http://f .com/' ) ;
44
+ expect ( this . proxyRes . headers . location ) . to . eql ( 'http://backend .com/' ) ;
44
45
} ) ;
45
46
46
47
it ( 'takes precedence over autoRewrite' , function ( ) {
47
48
this . options . autoRewrite = true ;
48
49
httpProxy . setRedirectHostRewrite ( this . req , { } , this . proxyRes , this . options ) ;
49
- expect ( this . proxyRes . headers . location ) . to . eql ( 'http://' + this . options . hostRewrite + ' /') ;
50
+ expect ( this . proxyRes . headers . location ) . to . eql ( 'http://ext-manual.com /' ) ;
50
51
} ) ;
51
52
} ) ;
52
53
53
54
context ( 'rewrites location host with autoRewrite' , function ( ) {
54
55
beforeEach ( function ( ) {
55
- this . options = {
56
- autoRewrite : true ,
57
- } ;
56
+ this . options . autoRewrite = true ;
58
57
} ) ;
59
58
[ 301 , 302 , 307 , 308 ] . forEach ( function ( code ) {
60
59
it ( 'on ' + code , function ( ) {
61
60
this . proxyRes . statusCode = code ;
62
61
httpProxy . setRedirectHostRewrite ( this . req , { } , this . proxyRes , this . options ) ;
63
- expect ( this . proxyRes . headers . location ) . to . eql ( 'http://' + this . req . headers . host + ' /') ;
62
+ expect ( this . proxyRes . headers . location ) . to . eql ( 'http://ext-auto.com /' ) ;
64
63
} ) ;
65
64
} ) ;
66
65
67
66
it ( 'not on 200' , function ( ) {
68
67
this . proxyRes . statusCode = 200 ;
69
68
httpProxy . setRedirectHostRewrite ( this . req , { } , this . proxyRes , this . options ) ;
70
- expect ( this . proxyRes . headers . location ) . to . eql ( 'http://f .com/' ) ;
69
+ expect ( this . proxyRes . headers . location ) . to . eql ( 'http://backend .com/' ) ;
71
70
} ) ;
72
71
73
72
it ( 'not when autoRewrite is unset' , function ( ) {
74
73
delete this . options . autoRewrite ;
75
74
httpProxy . setRedirectHostRewrite ( this . req , { } , this . proxyRes , this . options ) ;
76
- expect ( this . proxyRes . headers . location ) . to . eql ( 'http://f .com/' ) ;
75
+ expect ( this . proxyRes . headers . location ) . to . eql ( 'http://backend .com/' ) ;
77
76
} ) ;
78
77
} ) ;
79
78
80
79
context ( 'rewrites location protocol with protocolRewrite' , function ( ) {
81
80
beforeEach ( function ( ) {
82
- this . options = {
83
- protocolRewrite : 'https' ,
84
- } ;
81
+ this . options . protocolRewrite = 'https' ;
85
82
} ) ;
86
83
[ 301 , 302 , 307 , 308 ] . forEach ( function ( code ) {
87
84
it ( 'on ' + code , function ( ) {
88
85
this . proxyRes . statusCode = code ;
89
86
httpProxy . setRedirectHostRewrite ( this . req , { } , this . proxyRes , this . options ) ;
90
- expect ( this . proxyRes . headers . location ) . to . eql ( 'https://f .com/' ) ;
87
+ expect ( this . proxyRes . headers . location ) . to . eql ( 'https://backend .com/' ) ;
91
88
} ) ;
92
89
} ) ;
93
90
94
91
it ( 'not on 200' , function ( ) {
95
92
this . proxyRes . statusCode = 200 ;
96
93
httpProxy . setRedirectHostRewrite ( this . req , { } , this . proxyRes , this . options ) ;
97
- expect ( this . proxyRes . headers . location ) . to . eql ( 'http://f .com/' ) ;
94
+ expect ( this . proxyRes . headers . location ) . to . eql ( 'http://backend .com/' ) ;
98
95
} ) ;
99
96
100
97
it ( 'not when protocolRewrite is unset' , function ( ) {
101
98
delete this . options . protocolRewrite ;
102
99
httpProxy . setRedirectHostRewrite ( this . req , { } , this . proxyRes , this . options ) ;
103
- expect ( this . proxyRes . headers . location ) . to . eql ( 'http://f .com/' ) ;
100
+ expect ( this . proxyRes . headers . location ) . to . eql ( 'http://backend .com/' ) ;
104
101
} ) ;
105
102
106
103
it ( 'works together with hostRewrite' , function ( ) {
107
- this . options . hostRewrite = 'x .com'
104
+ this . options . hostRewrite = 'ext-manual .com'
108
105
httpProxy . setRedirectHostRewrite ( this . req , { } , this . proxyRes , this . options ) ;
109
- expect ( this . proxyRes . headers . location ) . to . eql ( 'https://x .com/' ) ;
106
+ expect ( this . proxyRes . headers . location ) . to . eql ( 'https://ext-manual .com/' ) ;
110
107
} ) ;
111
108
112
109
it ( 'works together with autoRewrite' , function ( ) {
113
110
this . options . autoRewrite = true
114
111
httpProxy . setRedirectHostRewrite ( this . req , { } , this . proxyRes , this . options ) ;
115
- expect ( this . proxyRes . headers . location ) . to . eql ( 'https://x2 .com/' ) ;
112
+ expect ( this . proxyRes . headers . location ) . to . eql ( 'https://ext-auto .com/' ) ;
116
113
} ) ;
117
114
} ) ;
118
115
} ) ;
0 commit comments