Skip to content

Commit

Permalink
Return an empty string for Request#host if HTTP_HOST and SERVER_NAME …
Browse files Browse the repository at this point in the history
…are both missing
  • Loading branch information
josh committed Aug 3, 2009
1 parent 162563d commit 6f40dc9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rack/request.rb
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions test/spec_rack_request.rb
Expand Up @@ -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
Expand Down

0 comments on commit 6f40dc9

Please sign in to comment.