fix: match request media types case-insensitively - #3095
Open
Keviniscool-boy wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
No unresolved review issues were identified.
Pull request overview
Fixes case-sensitive media-type matching for request body binding and multipart form parsing.
Changes:
- Match supported media types case-insensitively.
- Detect multipart forms without altering original headers or boundaries.
- Add regression tests for supported, unsupported, and multipart cases.
File summaries
| File | Description |
|---|---|
context.go |
Case-insensitive multipart detection |
context_test.go |
Multipart parsing regression tests |
bind.go |
Case-insensitive body media-type dispatch |
bind_test.go |
Media-type binding regression tests |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requests with a supported but mixed-case media type, such as
Content-Type: Application/JSON, currently fail body binding with HTTP 415.Context.FormValuesalso silently omits multipart body fields forMultipart/Form-Data, returning only query parameters. RFC 9110 section 8.3.1 specifies that media type and subtype tokens are case-insensitive.Normalize the media type token in
BindBodyand compare the complete multipart media type case-insensitively inFormValues. The original header and its parameters remain untouched, preserving case-sensitive multipart boundaries.Regression tests cover all five supported media types, multipart form fields alongside query parameters, preservation of the original header and a mixed-case boundary, and HTTP 415 for an unsupported media type. Before the fix, all five mixed-case binding cases fail with 415 and both mixed/uppercase multipart form cases lose their body fields; all pass after the fix.
Validation:
go test ./...(Windows)go test -race ./...(Ubuntu under WSL, Go 1.25.0)go vet ./...go run honnef.co/go/tools/cmd/staticcheck@v0.7.0 ./...go run golang.org/x/lint/golint@latest -set_exit_status ./...git diff --checkPrepared with assistance from OpenAI Codex.