diff --git a/internal/gateway/upstream.go b/internal/gateway/upstream.go index 8aeaf82..29451fb 100644 --- a/internal/gateway/upstream.go +++ b/internal/gateway/upstream.go @@ -1583,7 +1583,6 @@ func setV1Headers(header http.Header, protocol wire.Protocol, body []byte, ids i // requests carry a fixed anthropic-beta set; upstreamRequest adds // anthropic-version and the beta query. func setV2Headers(header http.Header, protocol wire.Protocol, ids identity.RequestIDs) { - header.Set("Accept", "application/json, text/event-stream") header.Set("x-opencode-client", "cli") rootSession := ids.Session if ids.ParentSession != "" { diff --git a/internal/httpx/bun.go b/internal/httpx/bun.go index 369319e..23363a8 100644 --- a/internal/httpx/bun.go +++ b/internal/httpx/bun.go @@ -532,8 +532,18 @@ func bunRequestHead(req *http.Request, body []byte) ([]byte, bool, error) { } var head strings.Builder head.WriteString(method + " " + req.URL.RequestURI() + " HTTP/1.1\r\n") + // fetch computes Content-Length itself when it has a body, so it appears in + // the common-header block instead of trailing the request. Header order is + // part of what a fingerprint sees, so it belongs where the runtime puts it. + wroteLength := false for _, name := range bunCommonHeaders { lower := strings.ToLower(name) + if lower == "content-length" && body != nil { + head.WriteString(name + ": " + strconv.Itoa(len(body)) + "\r\n") + delete(values, lower) + wroteLength = true + continue + } if value, ok := values[lower]; ok { head.WriteString(name + ": " + value + "\r\n") delete(values, lower) @@ -563,7 +573,7 @@ func bunRequestHead(req *http.Request, body []byte) ([]byte, bool, error) { if !hasEncoding { head.WriteString("Accept-Encoding: gzip, deflate, br, zstd\r\n") } - if body != nil { + if body != nil && !wroteLength { head.WriteString("Content-Length: " + strconv.Itoa(len(body)) + "\r\n") } head.WriteString("\r\n")