feat: support HTTP QUERY method (RFC 10008)#5459
Conversation
Add QUERY to normalized method records, safe HTTP methods, idempotent default, retryable methods, and fetch safe methods. Closes #5454
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5459 +/- ##
==========================================
- Coverage 93.46% 93.46% -0.01%
==========================================
Files 110 110
Lines 37106 37118 +12
==========================================
+ Hits 34682 34693 +11
- Misses 2424 2425 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
One correctness note before this lands: adding I'm creating issues/PRs for improved retries and caching on my fork (GenAI-assisted), I am happy to upstream those issues/PRs once I have reviewed them. |
…memory) Make streaming QUERY request bodies cacheable/deduplicable instead of bypassing them. Both interceptors buffer a stream body up to a configurable cap (maxRequestBodyKeySize, default 1 MiB) to compute the body-aware key: - body <= cap: buffered, hashed, cached/deduplicated (no re-upload on hit) - body > cap: reconstructed (read prefix + piped remainder) and forwarded uncached, keeping peak memory at ~cap (no OOM on huge bodies) Adds readRequestBodyForKey/isStreamingRequestBody to lib/util/cache.js, the maxRequestBodyKeySize option + validation to both interceptors, and types. Deliberately omits request-body prefix-hash checkpoints and the forward-then-abort-before-last-chunk trick: hashing is cheap relative to the transfer; prefix-optimistic dedup is unsound (bodies can diverge after the prefix); and aborting after uploading ~all of an unbufferable body saves nothing. Avoiding the upload of a body too large to buffer requires a protocol-level request digest (RFC 9530), not a client-side trick. Refs: nodejs#5454, nodejs#5459 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add comprehensive tests for HTTP QUERY (RFC 10008): - QUERY with string, Buffer, stream bodies - QUERY without body and with null body - Content-Type and Accept-Query headers - Content-Length header sending - Content-Length mismatch error handling - Fetch API with QUERY method - FormData body with QUERY - Redirect 301 (QUERY stays QUERY - safe method) - Redirect 303 (QUERY changes to GET)
QUERY responses depend on the request body (RFC 10008 §2.7), but the cache/deduplicate interceptors' cache keys ignore the request body. Removing QUERY from safeHTTPMethods prevents these interceptors from accepting QUERY, avoiding serving wrong responses. The fetch API's separate safeMethods list in web/fetch/constants.js still includes QUERY, which is correct for cache invalidation purposes.
Description
Adds support for the HTTP QUERY method standardized in RFC 10008 (June 2026), enabling safe/idempotent requests with bodies.
Changes
lib/core/util.js: AddedQUERYto normalized method records andsafeHTTPMethodslib/core/request.js: QUERY is idempotent by default (safe to retry)lib/handler/redirect-handler.js: Comment clarifying QUERY is safe (like GET) and won't change method on 301/302 redirectslib/handler/retry-handler.js: QUERY added to default retryable methodslib/web/fetch/constants.js: QUERY added tosafeMethodsfor the Fetch APICloses #5454