We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
$ go list -m github.com/ogen-go/ogen github.com/ogen-go/ogen v1.4.1
Yes
I created an OpenAPI spec that utilizes a custom user-defined header and has a Bearer security scheme:
openapi: 3.1.0 info: title: Simple API description: A simple API with header utilization version: 1.0.0 paths: /items: get: summary: Retrieve a list of items security: - bearerAuth: [] parameters: - name: X-Custom-Header in: header required: true description: Custom header for request schema: type: string responses: "200": description: A list of items content: application/json: schema: type: array items: type: string components: securitySchemes: bearerAuth: type: http scheme: bearer bearerFormat: JWT
Then I called an OPTIONS request to the /items path.
/items
There are headers Authorization, X-Custom-Header and Content-Type in the Access-Control-Allow-Headers header of the OPTIONS response for /items
Authorization
X-Custom-Header
Content-Type
Access-Control-Allow-Headers
The only CORS-allowed header is Content-Type
It seems like the Access-Control-Allow-Headers is hardcoded in the template gen/_template/cfg.tmpl:
gen/_template/cfg.tmpl
... MethodNotAllowed: func(w http.ResponseWriter, r *http.Request, allowed string) { status := http.StatusMethodNotAllowed if r.Method == "OPTIONS" { w.Header().Set("Access-Control-Allow-Methods", allowed) w.Header().Set("Access-Control-Allow-Headers", "Content-Type") status = http.StatusNoContent } else { w.Header().Set("Allow", allowed) } w.WriteHeader(status) }, ...
It can currently be mitigated by either setting this header in the reverse proxy or redefining the MethodNotAllowed function using ServerOptions.
MethodNotAllowed
I propose an addition to the signature of this function to include not only allowed methods but also allowed headers.
The text was updated successfully, but these errors were encountered:
You can override default handler via WithMethodNotAllowed option.
WithMethodNotAllowed
ogen/gen/_template/cfg.tmpl
Lines 258 to 265 in 4182357
Sorry, something went wrong.
No branches or pull requests
What version of ogen are you using?
Can this issue be reproduced with the latest version?
Yes
What did you do?
I created an OpenAPI spec that utilizes a custom user-defined header and has a Bearer security scheme:
Then I called an OPTIONS request to the
/items
path.What did you expect to see?
There are headers
Authorization
,X-Custom-Header
andContent-Type
in theAccess-Control-Allow-Headers
header of the OPTIONS response for/items
What did you see instead?
The only CORS-allowed header is
Content-Type
Probable cause
It seems like the
Access-Control-Allow-Headers
is hardcoded in the templategen/_template/cfg.tmpl
:It can currently be mitigated by either setting this header in the reverse proxy or redefining the
MethodNotAllowed
function using ServerOptions.I propose an addition to the signature of this function to include not only allowed methods but also allowed headers.
The text was updated successfully, but these errors were encountered: