Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let Host be automatically inferred on redirects #410

Merged
merged 1 commit into from
May 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/http/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,17 @@ def initialize(opts)

# Returns new Request with updated uri
def redirect(uri, verb = @verb)
req = self.class.new(
headers = self.headers.dup
headers.delete(Headers::HOST)

self.class.new(
:verb => verb,
:uri => @uri.join(uri),
:headers => headers,
:proxy => proxy,
:body => body,
:version => version
)

req[Headers::HOST] = req.uri.host
req
end

# Stream the request to a socket
Expand Down
14 changes: 14 additions & 0 deletions spec/lib/http/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,20 @@
expect(redirected["Host"]).to eq "blog.example.com"
end

context "with URL with non-standard port given" do
subject(:redirected) { request.redirect "http://example.com:8080" }

its(:uri) { is_expected.to eq HTTP::URI.parse "http://example.com:8080" }

its(:verb) { is_expected.to eq request.verb }
its(:body) { is_expected.to eq request.body }
its(:proxy) { is_expected.to eq request.proxy }

it "presets new Host header" do
expect(redirected["Host"]).to eq "example.com:8080"
end
end

context "with schema-less absolute URL given" do
subject(:redirected) { request.redirect "//another.example.com/blog" }

Expand Down