So i'm trying to implement something like Imgur, where an user who isn't a member on the website can upload, and continue to edit that upload (until the cookie is reset).
When looking at the conn
struct, there are 3 places where the user's cookie appears.
conn.cookies["_APPNAME_key"]
conn.req_cookies["_APPNAME_key"]
List.keyfind(conn.req_headers, "cookie", 0)
These all return the same cookie (except the last one has "_APPNAME_key=COOKIE" vs "COOKIE" for the other 3)
What is the difference between the three? Is there one I should use instead of the others?
conn.cookies
the request cookies with the response cookiesconn.req_cookies
the request cookies (without the response ones), of course there is coon.resp_cookies
for the response cookies.List.keyfind(conn.req_headers, "cookie", 0)
just get the cookies from request's headers, which is conn.req_cookies
.
You should use conn.req_cookies["_APPNAME_key"]
in your case.
See https://hexdocs.pm/plug/Plug.Conn.html#module-request-fields for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With