Skip to content

Add configurable preflight status code for CORS middleware #2765

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dneto
Copy link

@dneto dneto commented Apr 11, 2025

Hello! I'm adding support to configurable status code for CORS preflight response.

Changes:

  • middleware/cors.go:
    • Adds the field PreflightStatusCode to CORSConfig struct
    • Sets http.NoContent as default value for PreflightStatusCode field, keeping the original behavior
  • middleware/cors_test.go
    • Add TestCORSWithConfig_PreflightStatusCode with both default and custom status code scenarios

According do MDN Reference both 200 and 204 are allowed, but checking this spec it says any 2XX is an ok status which made me create PreflightStatusCode as an int rather than a bool ReturnStatusOkInPreflight or something like that.

@dneto dneto force-pushed the preflight_status_code branch from 7e4f71a to 2fabaf9 Compare April 11, 2025 00:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant