So I'm sure I'm trying to cheat here, but the ResponseWriter docs has a method 'Header()' which returns the Header object it's using. https://pkg.go.dev/net/http#ResponseWriter.Header
Now I'm getting a http.Response from somewhere else, and I want to copy across all the headers from that into my ResponseWriter.
Now, I could use a for loop like this:
for k := range resp.Header
w.Header().Add(k, resp.Header.Get(k))
}
Logically, it also made sense for me to just change the reference from the ResponseWriter's header, to the Response's header, however it seems like the ResponseWriter type is actively trying to stop me from doing that.
Something stupid like this comes to mind
w.Header() = resp.Header
Or
rwHeader := w.Header()
rwHeader = resp.Header
Obviously both of these make no sense and do not work at all, but hopefully conveys the idea of what I'm trying to do.
Can anyone offer an explanation of why what I'm trying to do doesn't work? Or maybe it does and I'm just not seeing the way to do it?