rs/cors

Returning http status codes - CORS always reports access-control-allow-origin

lsgroup opened this issue · 2 comments

Hi - using rs/cors with gorilla mux. When I return a http error code such as
http.Error(w, http.StatusText(http.StatusTooManyRequests), http.StatusTooManyRequests)
the client no longer sees the "HTTP 429 Too Many Requests", instead it sees a CORS error access-control-allow-origin.
Is there a way I can use rs/cors module and have it return the HTTP 429 instead of a CORS error?

I'm using rs/cors as per your examples:
handler := cors.Default().Handler(rtr)
if err := http.ListenAndServe(":3012",
(limitMiddleware(handler))); err != nil {
log.Fatalf("unable to start server: %s", err.Error())
}

the limitMiddleware function is what is returning different HTTP status codes.
Is there a way to use rs/cors using the "Use" function - and would that help in this situation?
rtr.Use(cors)
Great library, tried a dozen different ways to manually code the CORS headers and never did get it right. Thanks!

jub0bs commented

@lsgroup Please add a minimal reproducible example that illustrates the issue.

jub0bs commented

@rs No minimal reproducible example from the OP. I think it's safe to close this issue.