Quick question about calling Set-Cookie twice in a row

163 views
Skip to first unread message

atd...@gmail.com

unread,
Jul 14, 2020, 7:54:56 PM7/14/20
to golang-nuts
Hello,

As I am writing some tests, I was wondering what should be the correct behavior when http.SetCookie is called twice with cookies of a same name but different values.

For example, what should a user-agent see as the cookie value and hence, what should it return back to the server with the next request?


Many thanks!


B Carr

unread,
Jul 14, 2020, 11:57:30 PM7/14/20
to golang-nuts
In my application, the most recent cookie value with the same name is returned on the next request.

Marcin Romaszewicz

unread,
Jul 15, 2020, 12:19:06 AM7/15/20
to B Carr, golang-nuts
The Go http code calls Header.Add() on your cookie, and Header.Add will concatenate values together. If you want replacement semantics, you'll have to clearout the "Set-Cookie" header on the response, or only add your final cookie.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/442794c0-c906-4472-ba8a-6017a22e19e8o%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages