proxy/http: fix duplicated EOH when rewriting absolute-form to origin-form

When forwarding HTTP/1.x absolute-form requests from the HTTP inbound, we
serialize a new request line/headers and then append the buffered remainder.
However, the remainder starts at the original End-Of-Headers (EOH, CRLFCRLF),
so we ended up emitting two consecutive CRLFCRLF boundaries. That breaks
parsing for some servers, especially with chunked bodies or JSON payloads.

Strip a leading EOH from the remainder before concatenation so only one header
terminator is present.

This change is minimal and only affects the Absolute target format path. CONNECT
and SOCKS remain pure tunnels.
This commit is contained in:
muyuanjin
2025-11-19 14:07:04 +08:00
committed by eycorsican
parent 3918d1c04c
commit 409b9a4a6d

View File

@@ -162,6 +162,12 @@ impl HttpStream {
match head.target_format {
TargetFormat::Absolute => {
// drain() returns (before EOH, starting at EOH). To avoid duplicating
// the CRLFCRLF boundary when we rebuild headers below, drop the
// leading EOH from the remainder.
if rest_buf.starts_with(&EOH) {
let _ = rest_buf.drain(..EOH.len());
}
let path_and_query = head
.uri
.path_and_query()