feat: get option for defineQueryHandler (cacheable GET equivalence)#1449
Merged
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Relies on the HEAD->GET route fallback (#1452): with the `get` option, plain .get()/.query() registration now also covers HEAD requests. Co-Authored-By: Claude Fable 5 <[email protected]>
pi0x
force-pushed
the
feat/define-query-handler
branch
from
July 10, 2026 08:06
9795969 to
3d8ad75
Compare
pi0
marked this pull request as ready for review
July 10, 2026 08:07
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Stacked on #1448. Adds a
getoption todefineQueryHandlerimplementing RFC 10008 §2.3's cacheability guidance end-to-end: the same handler serves an equivalent, HTTP-cacheableGET, and successfulQUERYresponses advertise it viaContent-Location— no server-side result store needed.Behavior
getset, the handler context gainsqueryon both paths (body text onQUERY, URL param onGET/HEAD); without it, behavior is unchanged (typed via overloads).GETformat comes from?format=(customizable:get: { param, formatParam }); it may be omitted only when exactly one concrete (non-wildcard) format is accepted — silent defaulting across formats would change query semantics. AllGET-path rejections are400(per RFC 9110,415/422apply to request content, which aGEThas none of).Content-Locationpreserves the request's existing search params (aQUERYto/books?lang=enadvertises/books?lang=en&q=…), is built viaURLSearchParams, is skipped when the URL would exceed 2048 chars (long queries being the reasonQUERYexists), and is never set on theGETpath.HEADneeds no extra registration: h3 matches theGETroute automatically (feat: automatically match GET routes for HEAD requests #1452), the handler runs withevent.req.method === "HEAD", and the body is stripped downstream — so clients can revalidate/probe the advertised URL cheaply.405+Allow: GET, HEAD, QUERY;Accept-Querystays on every response including errors.Design review
The plan was adversarially reviewed by an agent against the codebase and the RFC text before implementation. Notable outcomes:
Content-Locationon 2xx confirmed as exactly RFC 10008 §2.3's mechanism (relative references valid per RFC 9110 §8.7).cache: {...}option (wiringhandleCacheHeaders) was dropped: it duplicates a documented one-liner, andhandleCacheHeaderscurrently force-prependspublictoCache-Controland ORsIf-None-Match/If-Modified-Since(RFC 9110 §13.2.2 wants ETag to take precedence) — worth fixing upstream before building sugar on it. Can open a separate issue.Changes
src/utils/query.ts:getoption + overloads;src/utils/internal/query-get.ts: GET resolution +Content-Locationhelpers (keepsquery.tsunder the size guideline)test/query.test.ts: 13 new matrix tests (round-trip identity, param preservation, encoding, wildcard/ambiguous/missing-param400s, length cutoff,HEADvia automatic GET matching,405Allow)examples/query.mjs: rewritten aroundget— drops the resultMap,queryIdhash, and/books/:idroute (~30 lines shorter); curl comments include aHEADprobeTest plan
main(includes feat: automatically match GET routes for HEAD requests #1452): full suite green — 1391 passed, no type errors, lint clean.Disclaimer
🤖 This PR was written by Claude Code (design and implementation reviewed and directed by a human).
🤖 Generated with Claude Code