Fork me on GitHub
#yada
<
2017-04-25
>
borkdude14:04:51

How do I set a cookie from Yada? I can do it with ring.middleware.cookies, but that feels like cheating

borkdude14:04:03

If I take the response from the context and assoc into the :cookies entry, it doesn’t work out the way I want

borkdude14:04:16

Although it somehow should behave the same as the ring middleware, I don’t see how

borkdude14:04:39

because once you return a response, Yada won’t touch it anymore

borkdude14:04:53

@dominicm Yeah I saw that, but how do I get the cookie into the context?

dominicm14:04:19

You mean read it @borkdude ?

borkdude14:04:41

@dominicm No put it there, before Yada produces the response like in the test

dominicm14:04:07

(merge (:response ctx)
   (redirect (-> ctx :parameters :query :response))
   {:cookies {"session" {:value "" :expires 0}}})
Something like this you mean?

borkdude14:04:36

Yeah something like that. Does that work?

dominicm14:04:04

getting annoyed with the indent. But yeah, that works.

borkdude14:04:19

Ah good, thanks for the example. What does it mean in the docs where it says in the manual: > When you need complete control over the response you should return the request-context’s response, modified if necessary. In which case yada will see that you want to be explicit and get out of your way. I thought this meant that Yada won’t touch your response any more, like a raw Ring response

dominicm14:04:19

Good question. One I must defer to @malcolmsparks 🙂

borkdude14:04:57

Ah, if I include this key :max-age 0 then it won’t send the header at all… that was tricky

dominicm14:04:46

cookies are built into ring

dominicm14:04:48

yada is using that

borkdude14:04:00

Yada has it’s own implementation of this

dominicm14:04:07

I don't think so. Yada is built on a ring-compliant server (aleph)

borkdude15:04:41

Gotcha:

(yada.cookies/cookies-coercer {"test" {:value "Foo"
                                         :domain "foo"
                                         :max-age 0}})
;;=> {:error {"test" {:max-age (not (instance? java.lang.String 0))}}}
This failed silently on me, I think I should have seen a warning

borkdude15:04:18

This seems a bit weird restriction

dominicm15:04:10

You don't need ring middleware to do cookies

borkdude15:04:23

@dominicm That’s not my point. You said “I think Yada is just using this cookies built into ring”. I thought you meant it used logic from Ring. It reimplements that cookie coercion (maps to strings) from Ring, but it doesn’t use the middleware directly.

borkdude15:04:37

Like the docstring says: > “Based on an original recipe ring.middleware.cookies my own includes chocolate-chip coercions.”

borkdude15:04:19

Ah, I was wrong, I see the error message, but not inside Emacs 🙂

borkdude15:04:13

Anyway, thanks for thinking along @dominicm, it works now