http icon indicating copy to clipboard operation
http copied to clipboard

Refactor `#cookie` API

Open ixti opened this issue 6 years ago • 3 comments

  1. HTTP::Response#cookies must return Array<HTTP::Cookies> - not jar.
  2. HTTP::Client#cookies should be either eliminated (IMO that's the best options) or become just a simple way of adding Cookie: header with no magic of cookies concatenation involved.

/cc @httprb/core

ixti avatar Mar 05 '19 03:03 ixti

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"

ixti avatar Mar 05 '19 04:03 ixti

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.

tarcieri avatar Mar 05 '19 05:03 tarcieri

Yes. Full cookie management belongs to session class. Here we should make it straight forward and simple to just pass cookies in and out.

ixti avatar Mar 05 '19 13:03 ixti