-
Notifications
You must be signed in to change notification settings - Fork 186
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
Rejected OPTIONS request when OPTIONS is configured in cors. #78
Comments
change and try 1.test OPPTIONS 2.test POST |
Working as expected. Your issue stems from a misunderstanding of how CORS works. The If the client (as opposed to the browser) sets a request header named Since that header name is not allowed by this library's default config, you need to explicitly allow it. Besides, you shouldn't manually set CORS response headers in addition to using a CORS middleware. |
Use this: // cors disable
corsConfig := cors.DefaultConfig()
corsConfig.AddAllowHeaders("Authorization") // Add Authorization to the list of allowed headers
corsConfig.AllowAllOrigins = true
r.Use(cors.New(corsConfig)) |
@approached That first comment is confusing. Instead, you must have meant // enable CORS |
Description
Having cors configurated in order to accept CORS requests, when sending an multipart/form-data, the following appears: Access to XMLHttpRequest at 'http://localhost:8080/add_project' from origin 'http://localhost:3000' has been blocked by CORS policy: Request header field authorization is not allowed by Access-Control-Allow-Headers in preflight response.
How to reproduce
React code:
Expectations
200 StatusAccepted
Actual result
Access to XMLHttpRequest at 'http://localhost:8080/add_project' from origin 'http://localhost:3000' has been blocked by CORS policy: Request header field authorization is not allowed by Access-Control-Allow-Headers in preflight response.
Environment
go version: go version go1.13.8 linux/amd64
gin version (or commit ref): latest
operating system: ubuntu 20.04
The text was updated successfully, but these errors were encountered: