|
3 | 3 | // |
4 | 4 | // You can configure it by passing an option struct to cors.New: |
5 | 5 | // |
6 | | -// c := cors.New(cors.Options{ |
7 | | -// AllowedOrigins: []string{"foo.com"}, |
8 | | -// AllowedMethods: []string{"GET", "POST", "DELETE"}, |
9 | | -// AllowCredentials: true, |
10 | | -// }) |
| 6 | +// c := cors.New(cors.Options{ |
| 7 | +// AllowedOrigins: []string{"foo.com"}, |
| 8 | +// AllowedMethods: []string{"GET", "POST", "DELETE"}, |
| 9 | +// AllowCredentials: true, |
| 10 | +// }) |
11 | 11 | // |
12 | 12 | // Then insert the handler in the chain: |
13 | 13 | // |
14 | | -// handler = c.Handler(handler) |
| 14 | +// handler = c.Handler(handler) |
15 | 15 | // |
16 | 16 | // See Options documentation for more options. |
17 | 17 | // |
@@ -210,7 +210,7 @@ func AllowAll() *Cors { |
210 | 210 | // as necessary. |
211 | 211 | func (c *Cors) Handler(next http.Handler) http.Handler { |
212 | 212 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
213 | | - if r.Method == http.MethodOptions && r.Header.Get("Access-Control-Request-Method") != "" { |
| 213 | + if r.Method == http.MethodOptions && r.Header.Get("Access-Control-Request-Method") != "" && r.Header.Get("Origin") != "" { |
214 | 214 | c.logf("Handler: Preflight request") |
215 | 215 | c.handlePreflight(w, r) |
216 | 216 | // Preflight requests are standalone and should stop the chain as some other |
|
0 commit comments