Skip to content

Commit 8f6cdec

Browse files
fix bug with HTTP 2.0
1 parent e83a46b commit 8f6cdec

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

proxy/proxy.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,17 @@ func (p *Server) forwardRequest(conn net.Conn, req *http.Request, https bool) {
344344
}
345345
resp.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))
346346

347+
// The downstream client (Claude) always communicates over HTTP/1.1.
348+
// However, Go's default HTTP client may negotiate an HTTP/2 connection
349+
// with the upstream server via ALPN during TLS handshake.
350+
// This can cause the response's Proto field to be set to "HTTP/2.0",
351+
// which would produce an invalid response for an HTTP/1.1 client.
352+
// To prevent this mismatch, we explicitly normalize the response
353+
// to HTTP/1.1 before writing it back to the client.
354+
resp.Proto = "HTTP/1.1"
355+
resp.ProtoMajor = 1
356+
resp.ProtoMinor = 1
357+
347358
// Copy response back to client
348359
err = resp.Write(conn)
349360
if err != nil {

0 commit comments

Comments
 (0)