Skip to content

fix: preserve original method case in CORS preflight responses#40

Open
lihan3238 wants to merge 1 commit into
go-chi:masterfrom
lihan3238:fix-27
Open

fix: preserve original method case in CORS preflight responses#40
lihan3238 wants to merge 1 commit into
go-chi:masterfrom
lihan3238:fix-27

Conversation

@lihan3238

Copy link
Copy Markdown

Fixes #27

Summary

Stop uppercasing AllowedMethods at config time and use case-insensitive comparison (strings.EqualFold) for method matching. This preserves the user-configured method case in Access-Control-Allow-Methods responses.

Before this fix, configuring AllowedMethods with lowercase methods (e.g., patch) would result in the response header being uppercased (PATCH), losing the original case.

Changes

  • Store AllowedMethods without uppercasing (preserve user's original case)
  • Use strings.EqualFold for case-insensitive method matching
  • Return the configured method name in Access-Control-Allow-Methods response header

Test

Added TestHandlePreflightLowercaseAllowedMethod from #27 — verifies that a lowercase method is preserved in the response.

Stop uppercasing AllowedMethods at config time and use case-insensitive
comparison (strings.EqualFold) for method matching. This preserves the
user-configured method case in Access-Control-Allow-Methods responses.

Fixes go-chi#27
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.

Allowing methods that are not uppercase should be possible but isn't

1 participant