Skip to content

Commit

Permalink
remove supportCORSRequest and support both CORS pre-flight and CORS r…
Browse files Browse the repository at this point in the history
…equests by default (#839)

Co-authored-by: jiangshaohua <[email protected]>
  • Loading branch information
coderabbit214 and jiangshaohua authored Oct 31, 2022
1 parent ba3c00a commit c75098f
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 8 deletions.
1 change: 0 additions & 1 deletion doc/reference/filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ allowedMethods: [GET]
| allowCredentials | bool | Indicates whether the request can include user credentials like cookies, HTTP authentication, or client-side SSL certificates | No |
| exposedHeaders | []string | Indicates which headers are safe to expose to the API of a CORS API specification | No |
| maxAge | int | Indicates how long (in seconds) the results of a preflight request can be cached. The default is 0 stands for no max age | No |
| supportCORSRequest | bool | When true, support CORS request and CORS preflight requests. By default, support only preflight requests. | No |

### Results

Expand Down
6 changes: 0 additions & 6 deletions pkg/filters/corsadaptor/corsadaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ type (
AllowCredentials bool `json:"allowCredentials" jsonschema:"omitempty"`
ExposedHeaders []string `json:"exposedHeaders" jsonschema:"omitempty"`
MaxAge int `json:"maxAge" jsonschema:"omitempty"`
// If true, handle requests with 'Origin' header. https://fetch.spec.whatwg.org/#http-requests
// By default, only CORS-preflight requests are handled.
SupportCORSRequest bool `json:"supportCORSRequest" jsonschema:"omitempty"`
}
)

Expand Down Expand Up @@ -122,9 +119,6 @@ func (a *CORSAdaptor) Handle(ctx *context.Context) string {

isPreflight := req.HTTPHeader().Get("Access-Control-Request-Method") != ""
isPreflight = isPreflight && (req.Method() == http.MethodOptions)
if !a.spec.SupportCORSRequest && !isPreflight {
return ""
}

rw := httptest.NewRecorder()
a.cors.HandlerFunc(rw, req.Std())
Expand Down
1 change: 0 additions & 1 deletion pkg/filters/corsadaptor/corsadaptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ name: cors
const yamlConfig = `
kind: CORSAdaptor
name: cors
supportCORSRequest: true
allowedOrigins:
- test.orig.test
`
Expand Down

0 comments on commit c75098f

Please sign in to comment.