Parsing HTTP header 'set-cookie' with HTTParty
<p>I'm using HTTParty for making HTTP requests and for using REST APIs. Now I want to re-use cookies set by a login page I called via POST.</p>

<pre><code>class SomeImporter
  include HTTParty

  def self.login
    response = self.post('https://www.example.com/login', :query =&gt; {:user =&gt; 'myusername', :password =&gt; 'secret'})
    self.default_cookies.add_cookies(response.header['set-cookie'])
    self.get('https://www.example.com/protected')
  end
end
</code></pre>

<p>The cookies are not set correctly with this code.
How to parse the 'set-cookie' header given by HTTParty correctly and set the cookies for next request?</p>