httparty
httparty copied to clipboard
Better way to access the CookieHash from the response?
If I am understanding, currently to access cookies you would need to do something like the following:
cookies = response.headers['Set-Cookie']
cookie_hash = CookieHash.new()
cookie_hash.add_cookies(cookies)
In this scenario, the cookie_hash is actually an array. If you wanted to access the cookie keys and values, you would need to do some more additional parsing outside of httparty. Am I missing something? Would it be useful if I created a branch that allowed us to do something like this:
cookies = response.cookies # Returns a CookieHash with keys and values
I've honestly never used cookies and it was added during a period of time I wasn't maintaining the app so I'm not really sure what is best here.
I suggest to use battle-tested Rack::Utils.parse_cookies_header
@dmitry that sounds like a good idea to me. Anything we need to do in httparty for this or just tell people to use that and then set cookies using httparty's cookie stuff that already exists?
@jnunemaker I'd say we could add a few lines about rack utility cookies methods:
Add values to the cookie: https://github.com/rack/rack/blob/4faf2c4e46cac2038feab722609ddaa983a54c2f/lib/rack/utils.rb#L218
Parse cookies: https://github.com/rack/rack/blob/4faf2c4e46cac2038feab722609ddaa983a54c2f/lib/rack/utils.rb#L207