I’m using Go to build a http server. How to change its “Referrer Policy”?
- I’ve followed the tutorial here to enable CORS in Go with
func enableCors(w *http.ResponseWriter) {
(*w).Header().Set("Access-Control-Allow-Origin", "*")
}
- and I’ve followed the syntax here to set
Referrer-Policy : same-origin
as well.
Yet, this is what I’m getting:
As the result, because my backend Golang app runs on one port and the frontend client app runs on another port.
Simply having different port numbers is already enough for two URLs to be considered different origins.
and my frontend client app is failing to access my Go based http server (It can access Python based http server just fine though). How to fix the problem please? Apparently the fix here is not working for me.
UPDATE:
The question is: is it responding to OPTION calls?
$ curl -I -X OPTIONS -H "Origin: test.com" localhost:8080/get
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Content-Type: application/json
Referrer-Policy: same-origin
Date: Mon, 28 Aug 2023 20:12:44 GMT
Content-Length: 72
$ curl -I -X OPTIONS -H "Origin: test.com" http://192.168.0.102:8080/get
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Content-Type: application/json
Referrer-Policy: same-origin
Date: Mon, 28 Aug 2023 21:18:27 GMT
Content-Length: 72
Are you setting that header for an OPTION request?
@BurakSerdar, I’ve tried to access it with
curl
for bothGET
andOPTIONS
and both headers are the same. Do you want me to post the result of header for an OPTION request?Not that, but posting the handler code might help, especially where you set that header.
did you mean my
func enableCors
in OP? It’s the same as stackhawk.com/blog/…That article does not show how the handler is registered. The question is: is it responding to OPTION calls?
Show 3 more comments