Attention! You must install the
http-cookie gem to use this feature.
cookies plugin seamlessly creates the concept of a stateful session, i.e. all requests flowing through it will share and update the cookie store.
A user can also pass the initial set of cookies when starting the session, though.
How to pass cookies:
http = HTTPX.plugin(:cookies) http.cookies("foo" => "bar").get("https://example.com")
But this is the ideal scenario:
http = HTTPX.plugin(:cookies) response = http.get("https://example.com/setscookies") #=> "302 ... Location: https://example.com/another ... Set-Cookie: aadm...." response = http.get(response.headers["location"]) => Sends the cookie information
This plugin also works seamlessly with the
follow_redirects plugin, in the redirections setting a session cookie will be respected:
http = HTTPX.plugin(:cookies, :follow_redirects) response = http.get("https://example.com/setscookies") #=> will redirect to "https://example.com/another" and set the cookie