Skip to content

fix: return 405 for wrong method, scope CORS allowed methods#3

Merged
pgagnidze merged 2 commits into
mainfrom
fix/method-handling
Mar 22, 2026
Merged

fix: return 405 for wrong method, scope CORS allowed methods#3
pgagnidze merged 2 commits into
mainfrom
fix/method-handling

Conversation

@pgagnidze

@pgagnidze pgagnidze commented Mar 21, 2026

Copy link
Copy Markdown
Member

Summary

Fixes #2 - two issues with HTTP method handling:

  • 405 instead of 404: When a request targets a valid path but uses an unsupported HTTP method, the server now returns 405 Method Not Allowed with an Allow header listing the registered methods, instead of 404 Not Found.
  • Scoped CORS methods: The Access-Control-Allow-Methods header now reflects only the methods actually registered for the requested path (on both preflight and 405 responses), rather than hardcoding all methods globally.

Test plan

  • busted passes (3 new tests for methods_for_path)
  • luacheck . and stylua --check . pass
  • PUT /heartbeat returns 405 with Allow: GET, OPTIONS when only GET is registered
  • OPTIONS /heartbeat preflight returns Access-Control-Allow-Methods: GET, OPTIONS
  • GET /nonexistent still returns 404
  • Wildcard routes (router.all) continue to match all methods

@pgagnidze pgagnidze force-pushed the fix/method-handling branch 4 times, most recently from 376a339 to c1e0527 Compare March 22, 2026 05:50
When a request targets a valid path but uses an unsupported HTTP method,
the server now returns 405 with an Allow header listing the actual
methods registered for that path, instead of returning 404.

The Access-Control-Allow-Methods CORS header now reflects only the
methods registered for the requested path (on both preflight and 405
responses), rather than advertising all methods globally.

Closes #2
@pgagnidze pgagnidze force-pushed the fix/method-handling branch from c1e0527 to 161e591 Compare March 22, 2026 05:52
@pgagnidze pgagnidze merged commit 394aafc into main Mar 22, 2026
3 checks passed
@pgagnidze pgagnidze deleted the fix/method-handling branch March 22, 2026 12:10
@pgagnidze pgagnidze mentioned this pull request Mar 22, 2026
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.

Method handling

1 participant