Fork me on GitHub
#aleph
<
2024-02-08
>
valerauko05:02:50

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?

valerauko05:02:40

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.

Matthew Davidson (kingmob)10:02:48

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?

valerauko11:02:39

It didn't work because the (:set-cookie headers) is a string (the cookies concatenated with comma) not a vector

Matthew Davidson (kingmob)11:02:49

Yeah, that fits with the spec. Cookie headers are unusual in having a substructure.

Matthew Davidson (kingmob)11:02:47

(Well, not THAT unusual, but still)

valerauko12:02:44

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