Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Return an empty string for Request#host if HTTP_HOST and SERVER_NAME …

…are both missing
  • Loading branch information...
commit 6f40dc99e3380efb4adccf8bfb4d07441bede8fb 1 parent 162563d
@josh josh authored
Showing with 6 additions and 1 deletion.
  1. +1 −1  lib/rack/request.rb
  2. +5 −0 test/spec_rack_request.rb
View
2  lib/rack/request.rb
@@ -65,7 +65,7 @@ def content_charset
def host
# Remove port number.
- (@env["HTTP_HOST"] || @env["SERVER_NAME"]).gsub(/:\d+\z/, '')
+ (@env["HTTP_HOST"] || @env["SERVER_NAME"]).to_s.gsub(/:\d+\z/, '')
end
def script_name=(s); @env["SCRIPT_NAME"] = s.to_s end
View
5 test/spec_rack_request.rb
@@ -37,6 +37,11 @@
req = Rack::Request.new \
Rack::MockRequest.env_for("/", "SERVER_NAME" => "example.org:9292")
req.host.should.equal "example.org"
+
+ env = Rack::MockRequest.env_for("/")
+ env.delete("SERVER_NAME")
+ req = Rack::Request.new(env)
+ req.host.should.equal ""
end
specify "can parse the query string" do
Please sign in to comment.
Something went wrong with that request. Please try again.