File tree Expand file tree Collapse file tree 2 files changed +4
-33
lines changed Expand file tree Collapse file tree 2 files changed +4
-33
lines changed Original file line number Diff line number Diff line change 11package serverHandler
22
33import (
4- "../util"
54 "net/http"
6- "strings"
75)
86
9- func (h * handler ) cors (w http.ResponseWriter , r * http. Request ) {
7+ func (h * handler ) cors (w http.ResponseWriter ) {
108 header := w .Header ()
119
1210 header .Set ("Access-Control-Allow-Origin" , "*" )
13-
14- if r .Method != http .MethodOptions {
15- return
16- }
17-
18- // Access-Control-Allow-Methods
19- acAllowMethods := []string {
20- http .MethodGet ,
21- http .MethodHead ,
22- http .MethodPost ,
23- http .MethodPut ,
24- http .MethodDelete ,
25- http .MethodOptions ,
26- http .MethodTrace ,
27- }
28- acReqMethods := r .Header ["Access-Control-Request-Method" ]
29- if len (acReqMethods ) > 0 {
30- acReqMethod := acReqMethods [0 ]
31- if ! util .Contains (acAllowMethods , acReqMethod ) {
32- acAllowMethods = append (acAllowMethods , acReqMethod )
33- }
34- }
35- header .Set ("Access-Control-Allow-Methods" , strings .Join (acAllowMethods , ", " ))
36-
37- // Access-Control-Allow-Headers
38- acAllowHeaders := r .Header ["Access-Control-Request-Headers" ]
39- if len (acAllowHeaders ) > 0 {
40- header .Set ("Access-Control-Allow-Headers" , strings .Join (acAllowHeaders , ", " ))
41- }
11+ header .Set ("Access-Control-Allow-Methods" , "*" )
12+ header .Set ("Access-Control-Allow-Headers" , "*" )
4213}
Original file line number Diff line number Diff line change @@ -104,7 +104,7 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
104104 h .header (w )
105105
106106 if data .CanCors {
107- h .cors (w , r )
107+ h .cors (w )
108108 }
109109
110110 if data .IsMutate {
You can’t perform that action at this time.
0 commit comments