@@ -47,6 +47,7 @@ type Options struct {
47
47
AllowOriginRequestFunc func (r * http.Request , origin string ) bool
48
48
// AllowedMethods is a list of methods the client is allowed to use with
49
49
// cross-domain requests. Default value is simple methods (HEAD, GET and POST).
50
+ // If the special "*" value is present in the list, all methods will be allowed.
50
51
AllowedMethods []string
51
52
// AllowedHeaders is list of non simple headers the client is allowed to use with
52
53
// cross-domain requests.
@@ -97,6 +98,8 @@ type Cors struct {
97
98
allowedOriginsAll bool
98
99
// Set to true when allowed headers contains a "*"
99
100
allowedHeadersAll bool
101
+ // Set to true when allowed methods contains a "*"
102
+ allowedMethodsAll bool
100
103
allowCredentials bool
101
104
optionPassthrough bool
102
105
}
@@ -169,6 +172,13 @@ func New(options Options) *Cors {
169
172
c .allowedMethods = []string {http .MethodGet , http .MethodPost , http .MethodHead }
170
173
} else {
171
174
c .allowedMethods = convert (options .AllowedMethods , strings .ToUpper )
175
+ for _ , h := range options .AllowedMethods {
176
+ if h == "*" {
177
+ c .allowedMethodsAll = true
178
+ c .allowedMethods = nil
179
+ break
180
+ }
181
+ }
172
182
}
173
183
174
184
return c
@@ -392,6 +402,9 @@ func (c *Cors) isOriginAllowed(r *http.Request, origin string) bool {
392
402
// isMethodAllowed checks if a given method can be used as part of a cross-domain request
393
403
// on the endpoint
394
404
func (c * Cors ) isMethodAllowed (method string ) bool {
405
+ if c .allowedMethodsAll {
406
+ return true
407
+ }
395
408
if len (c .allowedMethods ) == 0 {
396
409
// If no method allowed, always return false, even for preflight request
397
410
return false
0 commit comments