http
http copied to clipboard
Refactor `#cookie` API
HTTP::Response#cookiesmust returnArray<HTTP::Cookies>- not jar.HTTP::Client#cookiesshould be either eliminated (IMO that's the best options) or become just a simple way of addingCookie:header with no magic of cookies concatenation involved.
/cc @httprb/core
Right now #cookies passing is somewhat weird (IMO):
def cookie_header(response)
response.parse(:json).dig("headers", "Cookie")
end
http = HTTP.cookies(:a => 1, :b => 2).cookies(:a => 3)
cookie_header http.get("https://httpbin.org/headers")
# => "a=3; b=2"
cookie_header http.get("https://httpbin.org/headers", :cookies => { :a => 4 })
# => "4"
http = http.headers("Cookie" => "a=1;f=6")
cookie_header http.get("https://httpbin.org/headers")
# "a=1;f=6; a=3; b=2"
cookie_header http.get("https://httpbin.org/headers", :cookies => { :a => 4 })
# "a=1;f=6; 4"
The CookieJar integration is definitely screwed up, and belongs on a hypothetical session type (#306), IMO.
I would agree with your assessment that this API needs changed and is presently awkward/asymmetrical.
Yes. Full cookie management belongs to session class. Here we should make it straight forward and simple to just pass cookies in and out.