Skip to content

Commit edf3e04

Browse files
committed
improve
1 parent e6741b9 commit edf3e04

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-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 {

tests/integration/cors_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func TestCORS(t *testing.T) {
5555
// OPTIONS userinfo for non-CORS
5656
req = NewRequest(t, "OPTIONS", "/#/oauth/userinfo")
5757
resp = MakeRequest(t, req, http.StatusMethodNotAllowed)
58+
assert.NotContains(t, resp.Header().Values("Vary"), "Origin")
5859
})
5960
})
6061

0 commit comments

Comments
 (0)