fix(http): falsy ClientRequest method defaults to GET instead of throwing (#4970) - #4978
Merged
Merged
Conversation
…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.
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.
Fixes #4970.
Problem
new ClientRequest({ method: '' })threwTypeError [ERR_INVALID_HTTP_TOKEN]: Method must be a valid HTTP token [""]. Node only token-validates a truthy method string (if (methodIsString && method)inlib/_http_client.js); a falsymethod('',undefined,null) falls through to the'GET'default. The #4907 validation over-fired on the empty string, regressingtest-http-client-defaults(which #4904 had fixed).Fix
crates/perry-ext-http/src/validation.rs—validate_client_optionsskips the HTTP-token check for an emptymethodstring. A non-empty invalid token (e.g.'\0','B@D') still throwsERR_INVALID_HTTP_TOKENwith the same message.crates/perry-ext-http/src/lib.rs—method_from_optionstreats''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 injs_http_client_request_standalone_newis removed.Verification
All compiled with the patched binary via
perry compilefrom the workspace root (auto-optimize, ext-http linked), staged with thetest-compat/node-core/shimcommon:test-http-client-defaults.js(Node v22test/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) #4907method: ''/undefined/absent →'GET','B@D'→ERR_INVALID_HTTP_TOKEN,'post'→'POST') matchesnode --experimental-strip-typesbyte-for-bytecargo fmt --checkand the 2000-line file-size gate are greenCode-only PR — no version bump / changelog (maintainer folds metadata at merge).