Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.

Commit

Permalink
Fix: HTTP_HOST header was getting a trailing ':' appended when no por…
Browse files Browse the repository at this point in the history
…t was specified.
  • Loading branch information
ihoka committed May 30, 2010
1 parent 6890e3b commit 814e3ed
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
5 changes: 3 additions & 2 deletions lib/rack/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,9 @@ def env_for(path, env)
uri = URI.parse(path)
uri.path = "/#{uri.path}" unless uri.path[0] == ?/
uri.host ||= @default_host

env["HTTP_HOST"] = "#{uri.host}:#{uri.port}"

port = uri.port ? ":#{uri.port}" : ''
env["HTTP_HOST"] = "#{uri.host}#{port}"

env = default_env.merge(env)

Expand Down
11 changes: 8 additions & 3 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,14 @@ def check(*args)
yielded.should be_true
end

it "sets the HTTP host" do
send(verb, "http://example.com:80/uri")
last_request.env["HTTP_HOST"].should == "example.com:80"
it "sets the HTTP_HOST header with port" do
send(verb, "http://example.org:8080/uri")
last_request.env["HTTP_HOST"].should == "example.org:8080"
end

it "sets the HTTP_HOST header without port" do
send(verb, "/uri")
last_request.env["HTTP_HOST"].should == "example.org"
end

context "for a XHR" do
Expand Down

0 comments on commit 814e3ed

Please sign in to comment.