From acaa1e007926c98faf823e991c15aeef768567e0 Mon Sep 17 00:00:00 2001 From: David Nichols Date: Mon, 30 Jan 2012 11:08:19 -0500 Subject: [PATCH 1/2] When an http response has two Set-Cookie in the header, response['Set-Cookie'] will return a single string. This string will be the two returned cookies separated by a comma, concatenated together. Instead this should use get_fields('Set-Cookie') which returns an array of returned cookie strings. --- lib/httparty/request.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/httparty/request.rb b/lib/httparty/request.rb index a4e47dbe..51ba8e49 100644 --- a/lib/httparty/request.rb +++ b/lib/httparty/request.rb @@ -226,7 +226,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 From e13bff21bd0f7218f20b76d21de683915019d22f Mon Sep 17 00:00:00 2001 From: David Nichols Date: Mon, 30 Jan 2012 11:16:26 -0500 Subject: [PATCH 2/2] The syntax of cookies is described in http://www.ietf.org/rfc/rfc2109.txt, section 4.1. Cookies are attribute-value pairs, so split should only return 2 values. This will allow '=' within the value of a cookie. --- lib/httparty/cookie_hash.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/httparty/cookie_hash.rb b/lib/httparty/cookie_hash.rb index 2a9dda18..15ffcda5 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