@@ -37,10 +37,10 @@ def app
37
37
last_response . body . should == "Proxied App2"
38
38
end
39
39
40
- it "should set the Host header" do
40
+ it "should set the Host header w/o default port " do
41
41
stub_request ( :any , 'example.com/test/stuff' )
42
42
get '/test/stuff'
43
- a_request ( :get , 'http://example.com/test/stuff' ) . with ( :headers => { "Host" => "example.com:80 " } ) . should have_been_made
43
+ a_request ( :get , 'http://example.com/test/stuff' ) . with ( :headers => { "Host" => "example.com" } ) . should have_been_made
44
44
end
45
45
46
46
it "should set the X-Forwarded-Host header to the proxying host by default" do
@@ -49,6 +49,20 @@ def app
49
49
a_request ( :get , 'http://example.com/test/stuff' ) . with ( :headers => { 'X-Forwarded-Host' => 'example.org' } ) . should have_been_made
50
50
end
51
51
52
+ describe "with non-default port" do
53
+ def app
54
+ Rack ::ReverseProxy . new ( dummy_app ) do
55
+ reverse_proxy '/test' , 'http://example.com:8080/'
56
+ end
57
+ end
58
+
59
+ it "should set the Host header including non-default port" do
60
+ stub_request ( :any , 'example.com:8080/test/stuff' )
61
+ get '/test/stuff'
62
+ a_request ( :get , 'http://example.com:8080/test/stuff' ) . with ( :headers => { "Host" => "example.com:8080" } ) . should have_been_made
63
+ end
64
+ end
65
+
52
66
describe "with preserve host turned off" do
53
67
def app
54
68
Rack ::ReverseProxy . new ( dummy_app ) do
@@ -194,6 +208,25 @@ def app
194
208
last_response . body . should == "Proxied Secure App"
195
209
end
196
210
211
+ it "should set the Host header w/o default port" do
212
+ stub_request ( :any , 'https://example.com/test/stuff' )
213
+ get '/test/stuff'
214
+ a_request ( :get , 'https://example.com/test/stuff' ) . with ( :headers => { "Host" => "example.com" } ) . should have_been_made
215
+ end
216
+ end
217
+
218
+ describe "with a https route on non-default port" do
219
+ def app
220
+ Rack ::ReverseProxy . new ( dummy_app ) do
221
+ reverse_proxy '/test' , 'https://example.com:8443'
222
+ end
223
+ end
224
+
225
+ it "should set the Host header including non-default port" do
226
+ stub_request ( :any , 'https://example.com:8443/test/stuff' )
227
+ get '/test/stuff'
228
+ a_request ( :get , 'https://example.com:8443/test/stuff' ) . with ( :headers => { "Host" => "example.com:8443" } ) . should have_been_made
229
+ end
197
230
end
198
231
199
232
describe "with a route as a string" do
0 commit comments