I'm trying to do the following: 1. upon receiving a http request (server side) 2. send a request to an upstream service with aleph client 3. there will be one or more cookies set in the response 4. I want to pass on these cookies (without using their values at all on the server side) and add a few more Does aleph provide some utilities to handle this?
Not sure why that didn't work off the top of my head, but 99% of the cookie code is in a.h.client-middleware , so I'd look there. They're tagged :no-doc, but are public.
In particular, look at aleph.http.client-middleware/add-cookie-header, aleph.http.client-middleware/merge-cookies and aleph.http.client-middleware/decode-set-cookie-header . One of those might be what you're looking for?
It didn't work because the (:set-cookie headers) is a string (the cookies concatenated with comma) not a vector
Yeah, that fits with the spec. Cookie headers are unusual in having a substructure.
(Well, not THAT unusual, but still)
Yet if I concat-join my new cookies onto that set-cookie string it sends only one weird big set-cookie header instead of each separately
My idea was something like
(let [response @(fetch upstream)
additional-cookies ["foo=bar" "a=b"]]
{:status 200
:headers (update (:headers response) "set-cookie" concat additional-cookies})
but this method did not work.