Skip to content

feat: add QUERY method (core support)#1445

Merged
pi0 merged 1 commit into
h3js:mainfrom
bizprat:feat/query-method
Jul 9, 2026
Merged

feat: add QUERY method (core support)#1445
pi0 merged 1 commit into
h3js:mainfrom
bizprat:feat/query-method

Conversation

@bizprat

@bizprat bizprat commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds first-class support for the HTTP QUERY method from RFC 10008. #1441.

Changes

  • add QUERY to the HTTPMethod type
  • generate app.query(route, handler, opts) alongside the existing method helpers
  • preserve QUERY request bodies when using proxyRequest()
  • add focused routing, body parsing, body limit, and proxy regression tests
  • adjust the H3 bundle-size guard for the added public method helper

Non-goals

This keeps the first PR small and does not add Accept-Query utilities or opt-in content-type validation helpers. Those can be follow-up PRs if wanted.

Tests

  • corepack pnpm vitest run test/router.test.ts test/body.test.ts test/proxy.test.ts test/unit/body-limit.test.ts
  • corepack pnpm lint
  • corepack pnpm vitest run test/router.test.ts test/body.test.ts test/proxy.test.ts test/unit/body-limit.test.ts test/bench/bundle.test.ts
  • corepack pnpm test

Summary by CodeRabbit

  • New Features

    • Added support for a new QUERY request method, including a matching route handler helper.
    • Requests using this method can now carry and process bodies consistently with other supported methods.
  • Tests

    • Added coverage for routing, body parsing, proxying, and request size limits with QUERY requests.
    • Tightened bundle size checks.

@bizprat
bizprat requested a review from pi0 as a code owner July 9, 2026 10:48
@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds first-class support for the HTTP "QUERY" method: extending the HTTPMethod type union, generating a query() method on H3 instances, including "QUERY" in payload-bearing methods for proxy/body handling, and adding corresponding tests plus adjusted bundle size thresholds.

Changes

QUERY Method Support

Layer / File(s) Summary
QUERY method type and route registration
src/types/h3.ts, src/h3.ts
HTTPMethod union and H3 class gain "QUERY"; prototype method injection loop generates a runtime query(route, handler, opts?) method.
Body handling for QUERY requests
src/utils/internal/proxy.ts, test/body.test.ts, test/unit/body-limit.test.ts
PayloadMethods now includes "QUERY"; tests verify readBody parsing and assertBodySize limits for QUERY requests.
Proxy forwarding and router dispatch tests
test/proxy.test.ts, test/router.test.ts, test/bench/bundle.test.ts
Tests confirm proxyRequest forwards QUERY bodies and router dispatches to .query() handlers; bundle size thresholds adjusted.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: pi0

Poem

A hop, a nibble, a brand-new verb —
"QUERY" joins GET without a curb,
Bodies travel safe and small,
Proxies pass them, one and all. 🐰
Thump-thump — tests all pass, hooray!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning Core QUERY support, body handling, proxying, and tests are present, but cache-header, CORS, and runtime/adapter parity audits from the issue are missing. Add the remaining QUERY parity coverage for cache headers, CORS preflight, and runtime/adapter pass-through, with regression tests.
✅ Passed checks (4 passed)
Check name Status Explanation
Out of Scope Changes check ✅ Passed No clear out-of-scope code changes are evident; the bundle-size tweak aligns with the new public API.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding first-class QUERY method support.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pi0x pi0x left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving — this is a clean, well-tested implementation of the core QUERY method support slice of #1441.

Covered ✅

  • "QUERY" added to the HTTPMethod union and the H3 class type declaration
  • app.query() shortcut (runtime method loop) and app.on("QUERY", …) both work; defineRoute inherits QUERY for free via HTTPMethod
  • readBody / readValidatedBody on QUERY bodies (body reading isn't method-gated) — covered by tests
  • assertBodySize / body limits — covered
  • Proxy forwards QUERY request bodies (QUERY added to PayloadMethods) — covered
  • Bundle-size budget bumped accordingly

All new tests pass locally (router, body, proxy, body-limit).

Follow-ups still needed to fully close #1441

This PR intentionally lands only the first sequenced slice. Remaining items from the issue for future PRs:

  1. setAcceptQuery() / getAcceptQuery() header utilities (Structured Fields List)
  2. Optional Content-Type validation helper (400 missing / 415 unsupported / 422 unprocessable)
  3. CORS preflight audit + test for QUERY (non-safelisted → always preflighted; note that an explicit methods allowlist must include "QUERY")
  4. Cache-header audit + test (If-None-Match / If-Modified-Since / 304)

Suggest keeping #1441 open with a checklist for the above.


Disclaimer: this review was generated with AI assistance (Claude Code) and reviewed before posting.

@pi0x pi0x changed the title feat: add QUERY method support feat: add QUERY method (core support) Jul 9, 2026
@pi0x pi0x mentioned this pull request Jul 9, 2026
13 tasks
@pi0
pi0 merged commit a6ba340 into h3js:main Jul 9, 2026
7 checks passed
pi0x pushed a commit that referenced this pull request Jul 9, 2026
Follow-up to QUERY method support (#1445) for RFC 10008.

- `setResponseAcceptQuery` / `getResponseAcceptQuery`: advertise and read the
  supported query media types via the `Accept-Query` response header, serialized
  as a Structured Fields (RFC 8941) List.
- `requireContentType`: opt-in request `Content-Type` validation throwing
  `400` (missing), `422` (malformed), or `415` (unsupported), with wildcard
  support (`*/*`, `type/*`).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
pi0x pushed a commit that referenced this pull request Jul 9, 2026
Follow-up to QUERY method support (#1445) for RFC 10008.

- `setResponseAcceptQuery`: advertise the supported query media types via the
  `Accept-Query` response header, serialized as a Structured Fields (RFC 8941)
  List.
- `requireContentType`: opt-in request `Content-Type` validation throwing
  `400` (missing), `422` (malformed), or `415` (unsupported), with wildcard
  support (`*/*`, `type/*`).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
pi0x pushed a commit that referenced this pull request Jul 9, 2026
Follow-up to QUERY method support (#1445) for RFC 10008.

- `setAcceptQuery`: advertise the supported query media types via the
  `Accept-Query` response header, serialized as a Structured Fields (RFC 8941)
  List.
- `requireContentType`: opt-in request `Content-Type` validation throwing
  `400` (missing), `422` (malformed), or `415` (unsupported), with wildcard
  support (`*/*`, `type/*`).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@coderabbitai coderabbitai Bot mentioned this pull request Jul 11, 2026
@bizprat
bizprat deleted the feat/query-method branch July 11, 2026 13:27
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.

3 participants