Skip to content

fix(http,assert): node:http argument/header/URL validation throws ERR_* (#4907) - #4948

Merged
proggeramlug merged 1 commit into
mainfrom
worktree-fix-4907-http-validation
Jun 10, 2026
Merged

proggeramlug merged 1 commit into
mainfrom
worktree-fix-4907-http-validation

Conversation

@proggeramlug

Copy link
Copy Markdown
Contributor

Fixes #4907 (part of #2132).

Adds the argument/header/URL validation node:http performs, throwing the matching ERR_*-coded error so the corpus' assert.throws(...) cases stop failing with "Missing expected exception".

Client (http.request / http.get / new ClientRequest)

New crates/perry-ext-http/src/validation.rs, wired into request_common / get_common / request_overload:

  • method non-token → TypeError [ERR_INVALID_HTTP_TOKEN] (Node's exact Method must be a valid HTTP token ["…"], raw method)
  • path chars outside !–ÿ → TypeError [ERR_UNESCAPED_CHARACTERS]
  • header field names → ERR_INVALID_HTTP_TOKEN; host header as array → ERR_INVALID_ARG_TYPE
  • protocol mismatch (mailto:/ftp: from url.parse, etc.) → TypeError [ERR_INVALID_PROTOCOL]
  • bare / scheme-less / host-less string URL (www.nodejs.org, 127.0.0.1, http://:80/) → TypeError [ERR_INVALID_URL]
  • insecureHTTPParser non-boolean / timeout non-number → ERR_INVALID_ARG_TYPE

Server (crates/perry-ext-http-server/src/response.rs)

  • res.setHeader → Error [ERR_HTTP_HEADERS_SENT] once sent, TypeError [ERR_INVALID_HTTP_TOKEN] for non-token names
  • res.removeHeader → Error [ERR_HTTP_HEADERS_SENT] once sent
  • res.writeEarlyHints validates hints → ERR_INVALID_ARG_TYPE / malformed link → ERR_INVALID_ARG_VALUE

assert.throws function-validator support (crates/perry-runtime/src/object/assert.rs)

The real wall for 3 of the target tests: assert.throws(fn, (err) => …) always failed "did not match the expected matcher" because expected_error_matches only handled regex / plain-object / instanceof matchers and never called a callable validator. It now calls a callable expected with the thrown error and matches on a strict true return (Node's validation-function semantics), trapping any throw the validator raises. Also covers assert.rejects / doesNotThrow / doesNotReject.

Validation

Target corpus tests pass (invalid-path-chars, request-invalid-method, client-headers-host-array, client-unescaped-path, client-invalid-path, invalid-urls, url.parse-protocol, client-insecure-http-parser, invalidheaderfield, early-hints-invalid-argument, response-add/remove-header-after-sent).

0 regressions: http node-suite 18/18, https 5/5, assert 70/70.

test-http-client-timeout-option still hangs on the pre-existing real-timeout event-loop gap (not a validation issue, out of scope).

…_* (#4907)

Add the argument/header/URL validation node:http performs, throwing the
matching ERR_*-coded error so the corpus' assert.throws(...) cases stop
failing with "Missing expected exception".

Client (http.request/get, new ClientRequest): method (ERR_INVALID_HTTP_TOKEN),
path (ERR_UNESCAPED_CHARACTERS), header field names (ERR_INVALID_HTTP_TOKEN),
host-header-as-array (ERR_INVALID_ARG_TYPE), protocol mismatch
(ERR_INVALID_PROTOCOL), bare/host-less string URL (ERR_INVALID_URL),
insecureHTTPParser/timeout option types (ERR_INVALID_ARG_TYPE).

Server (response.rs): res.setHeader/removeHeader throw ERR_HTTP_HEADERS_SENT
after headers are sent; setHeader rejects non-token names; res.writeEarlyHints
validates its hints argument (ERR_INVALID_ARG_TYPE / ERR_INVALID_ARG_VALUE).

assert.throws: expected_error_matches now handles the function-validator form
(assert.throws(fn, (err) => ...)) by calling the validator with the thrown
error and matching on a strict true return (Node semantics); also covers
rejects/doesNotThrow/doesNotReject.

0 regressions: http node-suite 18/18, https 5/5, assert 70/70.
@proggeramlug
proggeramlug force-pushed the worktree-fix-4907-http-validation branch from a40cb83 to 8b44e58 Compare June 10, 2026 20:05
@proggeramlug
proggeramlug merged commit 8c429be into main Jun 10, 2026
12 of 13 checks passed
@proggeramlug
proggeramlug deleted the worktree-fix-4907-http-validation branch June 10, 2026 20:08
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.

node:http: missing argument/header/URL validation (assert.throws → Missing expected exception)

1 participant