Skip to content

Commit 99f0fea

Browse files
committed
improve
1 parent e6741b9 commit 99f0fea

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

modules/public/public.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func FileHandlerFunc() http.HandlerFunc {
3333
assetFS := AssetFS()
3434
return func(resp http.ResponseWriter, req *http.Request) {
3535
if req.Method != "GET" && req.Method != "HEAD" {
36-
resp.WriteHeader(http.StatusBadRequest)
36+
resp.WriteHeader(http.StatusMethodNotAllowed)
3737
return
3838
}
3939
handleRequest(resp, req, assetFS, req.URL.Path)

routers/web/web.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,12 @@ func optionsCorsHandler() func(next http.Handler) http.Handler {
7979
if corsHandler != nil && r.Header.Get("Access-Control-Request-Method") != "" {
8080
corsHandler(next).ServeHTTP(w, r)
8181
} else {
82-
// it should explicitly deny OPTIONS requests if CORS is disabled, to avoid the following GET/POST handler to be called by the OPTIONS request
82+
// it should explicitly deny OPTIONS requests if CORS handler is executed, to avoid the following GET/POST handler to be incorrectly called by the OPTIONS request
8383
w.WriteHeader(http.StatusMethodNotAllowed)
8484
}
8585
return
8686
}
87+
// for non-OPTIONS requests, call the CORS handler to add some related headers like "Vary"
8788
if corsHandler != nil {
8889
corsHandler(next).ServeHTTP(w, r)
8990
} else {

0 commit comments

Comments
 (0)