mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2026-05-23 19:56:31 +03:00
lib/httpserver: handle preflight HTTP requests properly
Previously OPTIONS HTTP requests for CORS preflight checks would trigger the original request handler. This pull request fixes that behavior to align with https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS Fixes https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5563
This commit is contained in:
@@ -357,6 +357,12 @@ func handlerWrapper(w http.ResponseWriter, r *http.Request, rh RequestHandler) {
|
||||
r.URL.Path = path
|
||||
}
|
||||
|
||||
if r.Method == http.MethodOptions {
|
||||
EnableCORS(w, r)
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
|
||||
w = &responseWriterWithAbort{
|
||||
ResponseWriter: w,
|
||||
}
|
||||
@@ -511,6 +517,8 @@ func EnableCORS(w http.ResponseWriter, _ *http.Request) {
|
||||
return
|
||||
}
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
w.Header().Set("Access-Control-Allow-Methods", "*")
|
||||
w.Header().Set("Access-Control-Allow-Headers", "*")
|
||||
}
|
||||
|
||||
func pprofHandler(profileName string, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
Reference in New Issue
Block a user