Skip to content

Commit

Permalink
Remove the port number of HTTP_HOST and SERVER_NAME
Browse files Browse the repository at this point in the history
darcs-hash:20070228134524-4fc50-5d243c4c75a9fece6ffaa9421d631f9b7498b6e0.gz
  • Loading branch information
leahneukirchen committed Feb 28, 2007
1 parent b064d53 commit c95b751
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/rack/request.rb
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions test/spec_rack_request.rb
Expand Up @@ -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
Expand Down

0 comments on commit c95b751

Please sign in to comment.