Skip to content

Commit

Permalink
Fix redircetion with multiple Location headers
Browse files Browse the repository at this point in the history
Resolves: #585
  • Loading branch information
ixti committed Jan 14, 2020
1 parent d754159 commit ea8ac4c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
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

0 comments on commit ea8ac4c

Please sign in to comment.