Skip to content

fix(http): falsy ClientRequest method defaults to GET instead of throwing (#4970) - #4978

Merged
proggeramlug merged 1 commit into
mainfrom
fix/falsy-method-default-get-4970
Jun 11, 2026
Merged

fix(http): falsy ClientRequest method defaults to GET instead of throwing (#4970)#4978
proggeramlug merged 1 commit into
mainfrom
fix/falsy-method-default-get-4970

Conversation

@proggeramlug

Copy link
Copy Markdown
Contributor

Fixes #4970.

Problem

new ClientRequest({ method: '' }) threw TypeError [ERR_INVALID_HTTP_TOKEN]: Method must be a valid HTTP token [""]. Node only token-validates a truthy method string (if (methodIsString && method) in lib/_http_client.js); a falsy method ('', undefined, null) falls through to the 'GET' default. The #4907 validation over-fired on the empty string, regressing test-http-client-defaults (which #4904 had fixed).

Fix

  • crates/perry-ext-http/src/validation.rsvalidate_client_options skips the HTTP-token check for an empty method string. A non-empty invalid token (e.g. '\0', 'B@D') still throws ERR_INVALID_HTTP_TOKEN with the same message.
  • crates/perry-ext-http/src/lib.rsmethod_from_options treats '' as absent → 'GET', so every client path (http.request, http.get, the overload entry points, new ClientRequest) defaults uniformly; the now-redundant empty-method patch-up in js_http_client_request_standalone_new is removed.

Verification

All compiled with the patched binary via perry compile from the workspace root (auto-optimize, ext-http linked), staged with the test-compat/node-core/shim common:

  • test-http-client-defaults.js (Node v22 test/parallel) — runtime-fail → pass (exit 0)
  • test-http-request-invalid-method-error.js — still pass (method: '\0' is non-empty → still throws, exact message preserved); no re-break of node:http: missing argument/header/URL validation (assert.throws → Missing expected exception) #4907
  • Local repro (method: ''/undefined/absent → 'GET', 'B@D'ERR_INVALID_HTTP_TOKEN, 'post''POST') matches node --experimental-strip-types byte-for-byte
  • cargo fmt --check and the 2000-line file-size gate are green

Code-only PR — no version bump / changelog (maintainer folds metadata at merge).

…wing (#4970)

Node only token-validates a *truthy* options.method
(`if (methodIsString && method)` in lib/_http_client.js); a falsy one
('', undefined, null) falls through to the 'GET' default. The #4907
validation over-fired and threw ERR_INVALID_HTTP_TOKEN on method: ''.

- validation.rs: skip the token check for an empty method string; a
  non-empty invalid token still throws ERR_INVALID_HTTP_TOKEN.
- method_from_options: treat '' as absent -> 'GET' (covers http.request,
  http.get, the overload paths, and new ClientRequest uniformly), and
  drop the now-redundant empty-method patch-up in
  js_http_client_request_standalone_new.

Verified: test-http-client-defaults (regression) and
test-http-request-invalid-method-error (#4907, method '\0' still
throws) both pass; repro matches node --experimental-strip-types
byte-for-byte.
@proggeramlug
proggeramlug merged commit b62cb95 into main Jun 11, 2026
12 of 13 checks passed
@proggeramlug
proggeramlug deleted the fix/falsy-method-default-get-4970 branch June 11, 2026 07:21
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.

regression: empty/falsy ClientRequest method '' throws instead of defaulting to GET (over-validation from #4907)

1 participant