Repository navigation
fix(request): include Allow header in 405 response - #1314
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthrough
Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
test/utils.test.ts (1)
304-304: Avoid hard-codingAllowheader ordering in the assertions.
Allowis order-insensitive, so exact string matches here will fail on harmless internal changes like sorting or deduping. Comparing the parsed method set would keep the coverage while making the tests less brittle.♻️ Suggested test update
- expect(res405.headers.get("Allow")).toBe("POST, HEAD"); + expect(new Set(res405.headers.get("Allow")?.split(/\s*,\s*/))).toEqual( + new Set(["POST", "HEAD"]), + ); ... - expect(res405.headers.get("Allow")).toBe("GET, POST"); + expect(new Set(res405.headers.get("Allow")?.split(/\s*,\s*/))).toEqual( + new Set(["GET", "POST"]), + );Also applies to: 316-316
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@test/utils.test.ts` at line 304, The assertion currently hard-codes the exact string ordering for the Allow header (expect(res405.headers.get("Allow")).toBe("POST, HEAD")), which is brittle; instead retrieve the Allow header from res405 (and the other similar assertion), split on commas, trim each method, and compare as a set/array-insensitive collection to the expected methods (e.g., compare to a Set or sort both arrays) so the test asserts membership rather than ordering; update the assertions referencing res405.headers.get("Allow") accordingly in test/utils.test.ts.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@test/utils.test.ts`:
- Line 304: The assertion currently hard-codes the exact string ordering for the
Allow header (expect(res405.headers.get("Allow")).toBe("POST, HEAD")), which is
brittle; instead retrieve the Allow header from res405 (and the other similar
assertion), split on commas, trim each method, and compare as a
set/array-insensitive collection to the expected methods (e.g., compare to a Set
or sort both arrays) so the test asserts membership rather than ordering; update
the assertions referencing res405.headers.get("Allow") accordingly in
test/utils.test.ts.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 0fd93c2d-4a5e-4141-b8a9-a9ff5cb287ae
📒 Files selected for processing (2)
src/utils/request.tstest/utils.test.ts
Allow header in 405 response
Problem
Fixes #1200.
RFC 9110 §15.5.6 requires that a 405 Method Not Allowed response MUST include an
Allowheader field listing the methods that are permitted for the target resource.The current
assertMethodimplementation throws a bareHTTPError({ status: 405 })with noAllowheader, making the response technically non-compliant and unhelpful to clients.Fix
Normalize the
expectedargument to an array, add"HEAD"ifallowHeadistrue, then pass the resulting method list as theAllowheader toHTTPError:This directly follows the approach suggested by @sandros94 in the issue thread.
Tests
assertMethodtest to assertAllow: POST, HEADon the 405 response.["GET", "POST"]) assertingAllow: GET, POST.Verification
vitest run— 943/943 tests ✅oxlint— 0 warnings, 0 errors ✅oxfmt --check— clean ✅Summary by CodeRabbit