HTTP server triggers 'Access-Control-Allow-Origin' header contains multiple values error

193 views
Skip to first unread message

paul.h....@gmail.com

unread,
Dec 6, 2016, 5:30:12 PM12/6/16
to golang-nuts
We have a simple http service running using the net/http package and I tried setting the Access-Control-Allow-Origin header value as in:

w.Header().Set("Access-Control-Allow-Origin", "*")

and when I do so the client side gets an error: "The 'Access-Control-Allow-Origin' header contains multiple values"

So it seems somewhere else the request origin is already added to the header although I can't find any mention of this in the docs.
What's the correct method for setting this header value so that it overrides what's there already?

Thanks for any pointers.

paul.h....@gmail.com

unread,
Dec 6, 2016, 5:50:02 PM12/6/16
to golang-nuts, paul.h....@gmail.com
Further to this... it seems the request origin is being "Add"ed to the header sometime after our handler gets called.
I tried doing a "Del" on the key before calling "Set" but this made no difference.

Ain

unread,
Dec 7, 2016, 1:40:33 AM12/7/16
to golang-nuts

kolmapäev, 7. detsember 2016 0:30.12 UTC+2 kirjutas paul.h....@gmail.com:
We have a simple http service running using the net/http package and I tried setting the Access-Control-Allow-Origin header value as in:

w.Header().Set("Access-Control-Allow-Origin", "*")

and when I do so the client side gets an error: "The 'Access-Control-Allow-Origin' header contains multiple values"

And how the raw header looks like (at the client side)?


So it seems somewhere else the request origin is already added to the header although I can't find any mention of this in the docs.

Do you use any http middleware / frameworks or is it plain net/http server?


ain 

Dave Cheney

unread,
Dec 7, 2016, 6:50:12 AM12/7/16
to golang-nuts
Grep for that string in GOROOT, it's not there, the net/http package is probably not adding it.

Can you create a stand alone program that shows the problem?

Dave

paul.h....@gmail.com

unread,
Dec 7, 2016, 10:50:46 AM12/7/16
to golang-nuts
Ok, I've since discovered that there's an nginx proxy in front of my service that is adding the header.

Sorry for the false alarm. :(

Problem resolved.
Reply all
Reply to author
Forward
0 new messages