From 1d388547ee7ad30bdb04a43bca4926dfce33951b Mon Sep 17 00:00:00 2001 From: Oleg Artyomov <47035805+ArtyomovOleg@users.noreply.github.com> Date: Sun, 8 Mar 2026 16:18:27 +0300 Subject: [PATCH] service/ccm: strip Accept-Encoding before forwarding to avoid untracked usage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When clients (e.g. Node.js Anthropic SDK) explicitly set Accept-Encoding: gzip, Go's http.Transport does not transparently decompress the response body, because it only does so when it added the header itself. This causes CCM's json.Unmarshal to receive raw gzip bytes, silently failing to parse usage data and leaving the usage counter unchanged. Fix: remove Accept-Encoding from the outgoing proxy request. Transport adds it automatically and transparently decompresses response.Body before CCM reads it. Wire compression (CCM→Anthropic) is preserved — Transport still negotiates gzip. Only CCM→localhost path is affected; compression on loopback has no practical benefit. --- service/ccm/service.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/service/ccm/service.go b/service/ccm/service.go index ba428060..944bedae 100644 --- a/service/ccm/service.go +++ b/service/ccm/service.go @@ -362,6 +362,13 @@ func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request) { } } + serviceOverridesAcceptEncoding := len(s.httpHeaders.Values("Accept-Encoding")) > 0 + if s.usageTracker != nil && !serviceOverridesAcceptEncoding { + // Strip Accept-Encoding so Go Transport adds it automatically + // and transparently decompresses the response for correct usage counting. + proxyRequest.Header.Del("Accept-Encoding") + } + anthropicBetaHeader := proxyRequest.Header.Get("anthropic-beta") if anthropicBetaHeader != "" { proxyRequest.Header.Set("anthropic-beta", anthropicBetaOAuthValue+","+anthropicBetaHeader)