Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix redirect with cookie support

When a response does not include cookies, the middleware sets the
"Cookies" header to nil which raises an exception in Net::HTTP.
  • Loading branch information...
commit 1fcb779fbc06f67aa04220edbc6518619ae1a204 1 parent 87c05b7
Marty Zalega authored mislav committed
View
5 lib/faraday_middleware/response/follow_redirects.rb
@@ -87,7 +87,10 @@ def perform_with_redirection(env, follows)
def update_env(env, request_body, response)
env[:url] += response['location']
- env[:request_headers][:cookies] = keep_cookies(env) if @options[:cookies]
+ if @options[:cookies]
+ cookies = keep_cookies(env)
+ env[:request_headers][:cookies] = cookies unless cookies.nil?
+ end
if transform_into_get?(response)
env[:method] = :get
View
7 spec/follow_redirects_spec.rb
@@ -141,6 +141,13 @@
stub.get('/found') { [200, {'Content-Type' => 'text/plain'}, ''] }
end.get('/').env[:request_headers][:cookies].should == cookies
end
+
+ it "not set cookies header on request when response has no cookies" do
+ conn = connection(:cookies => :all) do |stub|
+ stub.get('/') { [301, {'Location' => '/found'}, ''] }
+ stub.get('/found') { [200, {'Content-Type' => 'text/plain'}, ''] }
+ end.get('/').env[:request_headers].has_key?('Cookies').should == false
+ end
end
context "is an array of cookie names" do
Please sign in to comment.
Something went wrong with that request. Please try again.