How to easily read a response cookie?

14 views
Skip to first unread message

Slava Ptsarev

unread,
Jan 15, 2019, 8:54:28 AM1/15/19
to http.rb: a fast, easy-to-use Ruby HTTP client with a chainable API
I found it difficult to get a value of a response cookie.
I had to do either:
response.cookies.store.instance_variable_get('@jar')[domain][path][cookie_key].value

or
response['Set-Cookie'].find {|header| header.start_with? cookie_key= }.sub(cookie_key=, "")

Which both look quite cryptic. Is there a better way?

Tony Arcieri

unread,
Jan 17, 2019, 2:00:09 AM1/17/19
to http.rb: a fast, easy-to-use Ruby HTTP client with a chainable API
This is odd-looking syntax, but I think you want: response.cookies.cookies

There's some discussion of better cookie handling here:

Viacheslav Ptsarev

unread,
Jan 17, 2019, 5:43:48 AM1/17/19
to Tony Arcieri, http.rb: a fast, easy-to-use Ruby HTTP client with a chainable API
Thanks Tony! It's strange I didn't notice this method. Might be a good idea to add this to the Wiki.



чт, 17 янв. 2019 г. в 10:00, Tony Arcieri <bas...@gmail.com>:
--
You received this message because you are subscribed to the Google Groups "http.rb: a fast, easy-to-use Ruby HTTP client with a chainable API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to httprb+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages