Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support both CORS pre-flight and CORS requests by default #839

Merged
merged 1 commit into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
remove supportCORSRequest and support both CORS pre-flight and CORS r…
…equests by default
  • Loading branch information
jiangshaohua committed Oct 30, 2022
commit 34116e204cd1e33193ed04da48255748d9b02777
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