diff --git a/crates/liburlx/src/protocol/http/h1.rs b/crates/liburlx/src/protocol/http/h1.rs index 8d3e580..2df8425 100644 --- a/crates/liburlx/src/protocol/http/h1.rs +++ b/crates/liburlx/src/protocol/http/h1.rs @@ -823,7 +823,16 @@ where // Determine if connection can be reused let server_wants_close = ph.headers.get("connection").is_some_and(|v| v.eq_ignore_ascii_case("close")); - let can_reuse = keep_alive && !use_http10 && !server_wants_close && !body_read_to_eof; + // When --fail skips the body, unread data remains on the socket. Don't reuse + // the connection if the response had body framing (Content-Length or chunked), + // because the next request would read stale body bytes as headers (curl compat: test 1328). + let has_body_framing = ph.headers.contains_key("content-length") + || ph.headers.get("transfer-encoding").is_some_and(|te| te_contains_chunked(te)); + let can_reuse = keep_alive + && !use_http10 + && !server_wants_close + && !body_read_to_eof + && !(fail_skip && has_body_framing); let mut resp = Response::new(ph.status, ph.headers, response_body, url.to_string()); resp.set_header_original_names(ph.original_names);