Skip to content

fix: match request media types case-insensitively - #3095

Open
Keviniscool-boy wants to merge 1 commit into
labstack:masterfrom
Keviniscool-boy:codex/fix-case-insensitive-content-type
Open

fix: match request media types case-insensitively#3095
Keviniscool-boy wants to merge 1 commit into
labstack:masterfrom
Keviniscool-boy:codex/fix-case-insensitive-content-type

Conversation

@Keviniscool-boy

Copy link
Copy Markdown

Requests with a supported but mixed-case media type, such as Content-Type: Application/JSON, currently fail body binding with HTTP 415. Context.FormValues also silently omits multipart body fields for Multipart/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 BindBody and compare the complete multipart media type case-insensitively in FormValues. 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 --check

Prepared with assistance from OpenAI Codex.

Copilot AI lite review requested due to automatic review settings September 12, 2026 06:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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.

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.

2 participants