Skip to content

feat: handle OPTIONS on /anything#162

Closed
cyfung1031 wants to merge 1 commit into
jaredwray:mainfrom
cyfung1031:feat/anything-options-method
Closed

feat: handle OPTIONS on /anything#162
cyfung1031 wants to merge 1 commit into
jaredwray:mainfrom
cyfung1031:feat/anything-options-method

Conversation

@cyfung1031

@cyfung1031 cyfung1031 commented Jul 17, 2026

Copy link
Copy Markdown

Please check if the PR fulfills these requirements

  • Followed the Contributing and Code of Conduct guidelines.
  • Tests for the changes have been added (for bug fixes/features) with 100% code coverage.

What kind of change does this PR introduce? Feature — /anything now handles OPTIONS like every other method instead of 404ing.


Summary

/anything currently registers GET/POST/PUT/PATCH/DELETE but not OPTIONS, so an OPTIONS request to it 404s instead of being echoed back like every other method:

$ curl -s -o /dev/null -w "%{http_code}\n" -X OPTIONS http://127.0.0.1:3000/anything
404

I ran into this migrating a project's GM_xmlhttpRequest test suite onto mockhttp.org — a test exercising OPTIONS against /anything (the closest equivalent to httpbin/httpbun, which commonly return 200 for OPTIONS) got a 404 instead.

Fix

Registers fastify.options("/anything", ...) alongside the other methods, running through the exact same echo handler rather than special-casing it as a bare CORS-style 204. This mirrors the precedent already set by the /b/:id bin-capture route (src/routes/bins/capture.ts), which explicitly loops over ["get", "post", "put", "patch", "delete", "options"] and treats OPTIONS as just another method to record and echo — since "anything" is meant to accept anything, including a preflight-shaped request.

Test plan

  • Added a test asserting OPTIONS /anything returns 200 with method: "OPTIONS" in the echoed body.
  • pnpm test (lint + full vitest run with coverage) passes locally: 474 tests, 100% line coverage, no lint warnings.
  • Manually verified against a local tsx src/index.ts instance.

/anything currently registers GET/POST/PUT/PATCH/DELETE but not
OPTIONS, so an OPTIONS request to it 404s instead of being echoed back
like every other method - unlike httpbin/httpbun, which commonly
returns 200 for OPTIONS.

This mirrors the precedent already set by the /b/:id bin-capture
route, which explicitly registers OPTIONS alongside the other methods
and runs it through the same handler rather than special-casing it as
a bare CORS-style 204 - since "anything" is meant to accept anything,
including a preflight-shaped request.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request adds support for the OPTIONS HTTP method on the /anything route, allowing it to be handled by the same echo handler as other methods. A corresponding test case has been added to verify that OPTIONS requests return a 200 status code and echo back the request details. No review comments were provided, so there is no feedback to address.

@cyfung1031

Copy link
Copy Markdown
Author

Sorry for using Vibe Coding.

In one of my projects (https://github.com/scriptscat/scriptcat/),
I am considering to migrate from https://httpbun.com/ to https://mockhttp.org/
However, I found that OPTIONS is not supported yet.

Screenshot 2026-07-18 at 7 52 43

Hope you might consider to merge this PR for the API enhancement.

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