orthecreedence / carrier

A lightweight, async HTTP client
40 stars 9 forks source link

cookie support #4

Open nightshade427 opened 9 years ago

nightshade427 commented 9 years ago

I think the last thing I need to get off drakma is cookie support. Any plans to support this?

orthecreedence commented 9 years ago

TBH I've thought about cookie support for a while and it seems a bit out of carrier's scope. That's not to say it can't be done, but it's most likely something I'd create a separate project for and have some sort of guide on integration.

How do you normally use cookies in your calls? Is it just outgoing? Or do you accept cookies from responses and then return them later? Do they last past the current session (ie do you store them indefinitely and load them later)?

You technically could have cookie support already, by manually doing it in the :headers and :header-callback params, the only real piece missing is parsing the cookie data from the header into a hash and saving/loading the data (probably in JSON) to a file. I suppose the annoying bits are correctly sending the right cookie(s) based on domain/path/expiration.

Now that I think about it, the best way to do this (sorry, kind of stream of consciousness here) is to have a separate project, cl-cookie (or something), where you give it a cookie header from a response (ie (parse-cookies cookie-store (gethash "set-cookie" header))), it saves the values in-memory in a hash, then when you want to make a request, you do :headers (list :cookie (get-cookies cookie-store :domain "test.com" :path "/omg")).

Then you could store cookies to a file: (save-cookies cookie-store "/path/to/jar") or (load-cookies cookie-store "/path/to/jar").

I'll have to read the cookie spec a bit and figure out how domain/path work (right now I'm unclear on this) but the project should end up being pretty tiny, I think, and could integrate well with carrier.

Right now I'm stretched a bit thin, so it may be a bit before I get around to it.

nightshade427 commented 9 years ago

Basically I take a request in wookie proxy it through drakma, do stuff with the body and send back through wookie to the client the altered body and cookies.

I get a request from wookie. Take the cookies out using the wookie cookie support. Then I convert those cookie to drakma cookie jar format, and make a request with those cookies in place (proxy the wookie request basically). I then take the drama response body and do stuff with it. I then take the cookies from the previous drakma response and convert the cookie jar format to wookie response cookie format and send the response to the client with the altered body and new cookies (cookies altered to match domains etc).

nightshade427 commented 9 years ago

I like your cl-cookie idea ;)

orthecreedence commented 9 years ago

https://github.com/fukamachi/cl-cookie

Looks like exactly what we want.

nightshade427 commented 9 years ago

Can this get integrated into carrier? Can we reopen so we can talk about carrier integrating that lib?

orthecreedence commented 9 years ago

Yeah I don't seen why not, reopening.