Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add spec for testing default ports for last_effective_url

  • Loading branch information...
commit a6ce53eff7b03d9c82ae95553c36c522bdca106c 1 parent 043eb05
@wader wader authored
Showing with 60 additions and 0 deletions.
  1. +44 −0 spec/redirect_spec.rb
  2. +16 −0 spec/stallion.rb
View
44 spec/redirect_spec.rb
@@ -318,4 +318,48 @@ def response(r)
}
end
+ it "should not add default http port to redirect url that don't include it" do
+ EventMachine.run {
+ conn = EventMachine::HttpRequest.new('http://127.0.0.1:8090/redirect/http_no_port')
+ http = conn.get :redirects => 1
+ http.errback {
+ http.last_effective_url.to_s.should == 'http://host/'
+ EM.stop
+ }
+ }
+ end
+
+ it "should not add default https port to redirect url that don't include it" do
+ EventMachine.run {
+ conn = EventMachine::HttpRequest.new('http://127.0.0.1:8090/redirect/https_no_port')
+ http = conn.get :redirects => 1
+ http.errback {
+ http.last_effective_url.to_s.should == 'https://host/'
+ EM.stop
+ }
+ }
+ end
+
+ it "should keep default http port in redirect url that include it" do
+ EventMachine.run {
+ conn = EventMachine::HttpRequest.new('http://127.0.0.1:8090/redirect/http_with_port')
+ http = conn.get :redirects => 1
+ http.errback {
+ http.last_effective_url.to_s.should == 'http://host:80/'
+ EM.stop
+ }
+ }
+ end
+
+ it "should keep default https port in redirect url that include it" do
+ EventMachine.run {
+ conn = EventMachine::HttpRequest.new('http://127.0.0.1:8090/redirect/https_with_port')
+ http = conn.get :redirects => 1
+ http.errback {
+ http.last_effective_url.to_s.should == 'https://host:443/'
+ EM.stop
+ }
+ }
+ end
+
end
View
16 spec/stallion.rb
@@ -185,6 +185,22 @@ def self.call(env)
stable.response.status = 301
stable.response["Location"] = "http://$$$@$!%&^"
+ elsif stable.request.path_info == '/redirect/http_no_port'
+ stable.response.status = 301
+ stable.response["Location"] = "http://host/"
+
+ elsif stable.request.path_info == '/redirect/https_no_port'
+ stable.response.status = 301
+ stable.response["Location"] = "https://host/"
+
+ elsif stable.request.path_info == '/redirect/http_with_port'
+ stable.response.status = 301
+ stable.response["Location"] = "http://host:80/"
+
+ elsif stable.request.path_info == '/redirect/https_with_port'
+ stable.response.status = 301
+ stable.response["Location"] = "https://host:443/"
+
elsif stable.request.path_info == '/gzip'
io = StringIO.new
gzip = Zlib::GzipWriter.new(io)
Please sign in to comment.
Something went wrong with that request. Please try again.