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

Fix redircetion with multiple Location headers #587

Merged
merged 1 commit into from
Jan 14, 2020
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
3 changes: 2 additions & 1 deletion lib/http/redirector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def perform(request, response)

@response.flush

@request = redirect_to @response.headers[Headers::LOCATION]
# XXX(ixti): using `Array#inject` to return `nil` if no Location header.
@request = redirect_to(@response.headers.get(Headers::LOCATION).inject(:+))
@response = yield @request
end

Expand Down
13 changes: 13 additions & 0 deletions spec/lib/http/redirector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ def redirect_response(status, location)
expect(res.to_s).to eq "foo"
end

it "concatenates multiple Location headers" do
req = HTTP::Request.new :verb => :head, :uri => "http://example.com"
headers = HTTP::Headers.new

%w[http://example.com /123].each { |loc| headers.add("Location", loc) }

res = redirector.perform(req, simple_response(301, "", headers)) do |redirect|
simple_response(200, redirect.uri.to_s)
end

expect(res.to_s).to eq "http://example.com/123"
end

context "following 300 redirect" do
context "with strict mode" do
let(:options) { {:strict => true} }
Expand Down