Skip to content

Commit edfa4f1

Browse files
committed
Fix redircetion with multiple Location headers
Resolves: #585
1 parent d754159 commit edfa4f1

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/http/redirector.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ def perform(request, response)
5858

5959
@response.flush
6060

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

spec/lib/http/redirector_spec.rb

+13
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,19 @@ def redirect_response(status, location)
7676
expect(res.to_s).to eq "foo"
7777
end
7878

79+
it "concatenates multiple Location headers" do
80+
req = HTTP::Request.new :verb => :head, :uri => "http://example.com"
81+
headers = HTTP::Headers.new
82+
83+
%w[http://example.com /123].each { |loc| headers.add("Location", loc) }
84+
85+
res = redirector.perform(req, simple_response(301, "", headers)) do |redirect|
86+
simple_response(200, redirect.uri.to_s)
87+
end
88+
89+
expect(res.to_s).to eq "http://example.com/123"
90+
end
91+
7992
context "following 300 redirect" do
8093
context "with strict mode" do
8194
let(:options) { {:strict => true} }

0 commit comments

Comments
 (0)