Repository navigation
fix(ext/node): pass URL to kOnHeadersComplete when request has no headers - #33831
Conversation
…ders Enables tests/node_compat/runner/suite/test/parallel/test-http-parser.js Co-authored-by: Divy Srivastava <me@littledivy.com>
fibibot
left a comment
There was a problem hiding this comment.
LGTM. Subtle but correct fix for an edge case in on_headers_complete. CI fully green at this head (99 success, 1 skipped, 0 fail).
What I verified
The bug: the old skip_flush boolean had two definitions that didn't match what the rest of the code assumed:
let skip_flush = !inner.headers_flushed && !inner.header_fields.is_empty();A request with no headers (header_fields.is_empty() == true) and no prior flush (headers_flushed == false) would compute skip_flush = false, sending the code down the slow path that passes undefined for headers/url to parserOnHeadersComplete — expecting JS to read from parser._headers/_url. But nothing was ever flushed (the inner if guards on !header_fields.is_empty()), so JS would see no URL.
The fix (binding.rs:464-471, :510) decouples the two semantics:
let on_fast_path = !inner.headers_flushed;
if !on_fast_path && !inner.header_fields.is_empty() {
// Slow path's optional flush — only fires when there ARE leftover headers
}
// ...
let (headers, url) = if on_fast_path {
// Fast path: pass header_fields (possibly empty) + url directly
} else {
// Slow path: pass undefined, JS already has _headers/_url from flush
};Now:
on_fast_pathis purely "no priorkOnHeadersflush has happened in this request". Independent of whether the current batch has headers.- The URL gets passed regardless of whether
header_fieldsis empty (the bug the PR title fixes). - Slow path's flush stays gated on
!is_empty()(no point flushing nothing).
The rename skip_flush -> on_fast_path is also a clarity win — the original name was confusing because it answered the wrong question (whether to skip the flush, not which path to take).
Test enable (config.jsonc:1550): parallel/test-http-parser.js — the upstream Node test that exercises kOnHeadersComplete invariants directly via the binding. ✓
No concerns inline — the diff is small enough to walk in one pass and the semantics are clean.
…ders (denoland#33831) ## Summary Enables `test-http-parser` in node_compat suite. ## Test plan - [x] `cargo test --test node_compat -- test-http-parser` Co-authored-by: divybot <divybot@users.noreply.github.com> Co-authored-by: Divy Srivastava <me@littledivy.com>
Summary
Enables
test-http-parserin node_compat suite.Test plan
cargo test --test node_compat -- test-http-parser