fix: header parameter lookup should be case-insensitive#10
Conversation
Normalize header keys to lowercase before validation so that spec-defined lowercase names (e.g. x-client-id) match request headers in canonical case (e.g. X-Client-Id) from HTTP/1.1 clients. Previously the fallback str_lower(name) only lowercased the spec name, which is a no-op when the spec name is already lowercase.
|
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThis PR normalizes incoming request header keys to lowercase before header parameter validation and adds unit and conformance tests verifying case-insensitive header name matching across canonical, uppercase, and mixed-case header variants. ChangesCase-Insensitive Header Validation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 6✅ Passed checks (6 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Pull request overview
Fixes header parameter validation to be case-insensitive by normalizing incoming request header table keys to lowercase before parameter lookup/validation, aligning behavior with HTTP header case-insensitivity and OpenAPI expectations.
Changes:
- Lowercase all request header keys inside
params.validate()before validating header parameters. - Add unit tests covering spec/request header name casing combinations for header params.
- Add conformance tests asserting canonical/uppercase header keys pass validation.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| lib/resty/openapi_validator/params.lua | Normalizes request header keys to lowercase before header parameter validation. |
| t/unit/test_params.lua | Adds unit tests for case-insensitive header parameter matching across casing variants. |
| t/conformance/test_validate_header.lua | Adds conformance coverage for canonical/uppercase request header keys. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Spec has capitalized names (Authorization, Content-Type), not lowercase - Rename 'mixed case' test to 'uppercase' to match actual header keys used
Problem
Header validation fails when the OpenAPI spec defines lowercase header names (e.g.
x-client-id) but HTTP/1.1 clients send canonical case (e.g.X-Client-Id). The existing fallbackraw_values[str_lower(name)]only lowercases the spec name — a no-op when it's already lowercase.Fix
Normalize header table keys to lowercase before passing to
validate_param_group. This makes the existingstr_lower(name)fallback work correctly for all case combinations.Tests
Added unit tests covering:
x-client-idvsX-Client-Id)x-client-idvsX-CLIENT-ID)Authorizationvsauthorization)Summary by CodeRabbit
Bug Fixes
Tests