Skip to content

Commit 409b9a4

Browse files
muyuanjineycorsican
authored andcommitted
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.
1 parent 3918d1c commit 409b9a4

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

leaf/src/proxy/http/inbound/stream.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,12 @@ impl HttpStream {
162162

163163
match head.target_format {
164164
TargetFormat::Absolute => {
165+
// drain() returns (before EOH, starting at EOH). To avoid duplicating
166+
// the CRLFCRLF boundary when we rebuild headers below, drop the
167+
// leading EOH from the remainder.
168+
if rest_buf.starts_with(&EOH) {
169+
let _ = rest_buf.drain(..EOH.len());
170+
}
165171
let path_and_query = head
166172
.uri
167173
.path_and_query()

0 commit comments

Comments
 (0)