Permalink
Browse files

Remove the port number of HTTP_HOST and SERVER_NAME

darcs-hash:20070228134524-4fc50-5d243c4c75a9fece6ffaa9421d631f9b7498b6e0.gz
  • Loading branch information...
1 parent b064d53 commit c95b7516f239dc14b64608697d5ffe2af391261d @chneukirchen chneukirchen committed Feb 28, 2007
Showing with 8 additions and 1 deletion.
  1. +5 −1 lib/rack/request.rb
  2. +3 −0 test/spec_rack_request.rb
View
@@ -12,11 +12,15 @@ def body; @env["rack.input"] end
def scheme; @env["rack.url_scheme"] end
def script_name; @env["SCRIPT_NAME"].to_s end
def path_info; @env["PATH_INFO"].to_s end
- def host; @env["HTTP_HOST"] || @env["SERVER_NAME"] end
def port; @env["SERVER_PORT"].to_i end
def request_method; @env["REQUEST_METHOD"] end
def query_string; @env["QUERY_STRING"].to_s end
+ def host
+ # Remove port number.
+ (@env["HTTP_HOST"] || @env["SERVER_NAME"]).gsub(/:\d+\z/, '')
+ end
+
def script_name=(s); @env["SCRIPT_NAME"] = s.to_s end
def path_info=(s); @env["PATH_INFO"] = s.to_s end
@@ -28,6 +28,9 @@
specify "can figure out the correct host" do
req = Rack::Request.new(TestRequest.env({"HTTP_HOST" => "www2.example.org"}))
req.host.should.equal "www2.example.org"
+
+ req = Rack::Request.new(TestRequest.env({"SERVER_NAME" => "example.org:9292"}))
+ req.host.should.equal "example.org"
end
specify "can parse the query string" do

0 comments on commit c95b751

Please sign in to comment.