On Tue, Apr 26, 2016 at 4:13 PM, <
laxman.v...@gmail.com> wrote:
>
> Adding Set-Cookie to response.Header crashes. Headers can be added to
> Response headers using response.Header.Add() except cookies.
>
http://play.golang.org/p/Gwtc0rXQka
> newrsp.Header.Add("Set-Cookie", sslCookie.String()) ---> panics with
> error:panic serving
127.0.0.1:40698: assignment to entry in nil map
>
This crashes because response.Header is nil. You need to initialize it first.
eg. newrsp.Header = http.Header{}
Your use of http.SetCookie() also doesn't work because you're sending
the response body first, preventing any further headers from being
added.
This example works, it does set the cookie twice though.
https://play.golang.org/p/tKjt44y_5b