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

[FEATURE] Allow users to disable caching of preflight responses #246

Open
1 task done
jub0bs opened this issue Aug 31, 2023 · 0 comments · May be fixed by #250
Open
1 task done

[FEATURE] Allow users to disable caching of preflight responses #246

jub0bs opened this issue Aug 31, 2023 · 0 comments · May be fixed by #250

Comments

@jub0bs
Copy link

jub0bs commented Aug 31, 2023

Is there an existing feature request for this?

  • I have searched the existing feature requests

Is your feature request related to a problem? Please describe.

Omitting the Access-Control-Max-Age header from a preflight response leads browsers to cache that response for 5 seconds, whereas including

Access-Control-Max-Age: 0

in a preflight instructs browsers not to cache that preflight response. However, the CORS middleware ignores that distinction and takes a maxAge value of 0 as a cue to omit the Access-Control-Max-Age header. Therefore, it prevents its users from disabling caching of preflight responses.

Describe the solution that you would like.

Fortunately, since the CORS middleware uses the functional-options pattern (as opposed to exposing a config struct to users), retrofitting it to understand this distinction (0 value set/unset) should be straightforward. Maintainers could add customMaxAge bool field to the cors struct type and set it when the MaxAge option is called.

Describe alternatives you have considered.

Alternatively, maintainers could change the type of cors.maxAge from int to *int, where a nil value indicates that users haven't set a max age.

Anything else?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
1 participant