summary refs log tree commit
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2009-08-03 10:33:18 -0500
committerJoshua Peek <josh@joshpeek.com>2009-08-03 10:33:18 -0500
commit6f40dc99e3380efb4adccf8bfb4d07441bede8fb (patch)
treea557d7da85e9cf9b79db0f7dc44aa07a5440e41c
parent162563d04224cf8b9e57a3d15f13b0dbb04fde33 (diff)
downloadrack-6f40dc99e3380efb4adccf8bfb4d07441bede8fb.tar.gz
Return an empty string for Request#host if HTTP_HOST and SERVER_NAME are both missing
-rw-r--r--lib/rack/request.rb2
-rw-r--r--test/spec_rack_request.rb5
2 files changed, 6 insertions, 1 deletions
diff --git a/lib/rack/request.rb b/lib/rack/request.rb
index 4c4cf61a..248ce18d 100644
--- a/lib/rack/request.rb
+++ b/lib/rack/request.rb
@@ -65,7 +65,7 @@ module Rack
 
     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
diff --git a/test/spec_rack_request.rb b/test/spec_rack_request.rb
index 81f05eba..facbe753 100644
--- a/test/spec_rack_request.rb
+++ b/test/spec_rack_request.rb
@@ -37,6 +37,11 @@ context "Rack::Request" do
     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