diff --git a/lib/httparty/cookie_hash.rb b/lib/httparty/cookie_hash.rb index a7863cb4..119964f6 100644 --- a/lib/httparty/cookie_hash.rb +++ b/lib/httparty/cookie_hash.rb @@ -8,7 +8,7 @@ def add_cookies(value) merge!(value) when String value.split('; ').each do |cookie| - array = cookie.split('=') + array = cookie.split('=',2) self[array[0].to_sym] = array[1] end else diff --git a/lib/httparty/request.rb b/lib/httparty/request.rb index 69a15e4c..a8ade9b1 100644 --- a/lib/httparty/request.rb +++ b/lib/httparty/request.rb @@ -290,7 +290,7 @@ def capture_cookies(response) return unless response['Set-Cookie'] cookies_hash = HTTParty::CookieHash.new() cookies_hash.add_cookies(options[:headers]['Cookie']) if options[:headers] && options[:headers]['Cookie'] - cookies_hash.add_cookies(response['Set-Cookie']) + response.get_fields('Set-Cookie').each { |cookie| cookies_hash.add_cookies(cookie) } options[:headers] ||= {} options[:headers]['Cookie'] = cookies_hash.to_cookie_string end diff --git a/spec/httparty/cookie_hash_spec.rb b/spec/httparty/cookie_hash_spec.rb index 3ad243bb..dcfeafa4 100644 --- a/spec/httparty/cookie_hash_spec.rb +++ b/spec/httparty/cookie_hash_spec.rb @@ -35,6 +35,13 @@ @cookie_hash.length.should eql(1) @cookie_hash[:foo].should eql("tar") end + + it "should handle '=' within cookie value" do + @cookie_hash.add_cookies("first=one=1; second=two=2==") + @cookie_hash.keys.should include(:first, :second) + @cookie_hash[:first].should == 'one=1' + @cookie_hash[:second].should == 'two=2==' + end end describe 'with other class' do diff --git a/spec/httparty/request_spec.rb b/spec/httparty/request_spec.rb index 2a76fb23..a5f505e2 100644 --- a/spec/httparty/request_spec.rb +++ b/spec/httparty/request_spec.rb @@ -495,6 +495,16 @@ @request.options[:headers]['Cookie'].should match(/keep=me/) end + it "should handle multiple Set-Cookie headers between redirects" do + @redirect.add_field 'set-cookie', 'foo=bar; name=value; HTTPOnly' + @redirect.add_field 'set-cookie', 'one=1; two=2; HTTPOnly' + @request.perform + @request.options[:headers]['Cookie'].should match(/foo=bar/) + @request.options[:headers]['Cookie'].should match(/name=value/) + @request.options[:headers]['Cookie'].should match(/one=1/) + @request.options[:headers]['Cookie'].should match(/two=2/) + end + it 'should make resulting request a get request if it not already' do @request.http_method = Net::HTTP::Delete @request.perform.should == {"hash" => {"foo" => "bar"}}