httparty icon indicating copy to clipboard operation
httparty copied to clipboard

Better way to access the CookieHash from the response?

Open tomrossi7 opened this issue 9 years ago • 4 comments
trafficstars

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

tomrossi7 avatar May 26 '16 18:05 tomrossi7

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.

jnunemaker avatar Jun 06 '16 20:06 jnunemaker

I suggest to use battle-tested Rack::Utils.parse_cookies_header

dmitry avatar Jul 25 '16 14:07 dmitry

@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 avatar Jul 29 '16 12:07 jnunemaker

@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

dmitry avatar Jul 29 '16 13:07 dmitry