fix(ai): remove manual Accept-Encoding header so Mistral gzip responses decode#1198
Open
martinconstam wants to merge 1 commit into
Open
fix(ai): remove manual Accept-Encoding header so Mistral gzip responses decode#1198martinconstam wants to merge 1 commit into
martinconstam wants to merge 1 commit into
Conversation
…code The Mistral provider set `Accept-Encoding: gzip, deflate` manually on the RestClient. OkHttp only decompresses a gzip response transparently when it adds the Accept-Encoding header itself; setting it explicitly disables that, so the gzipped body reached Jackson undecoded and parsing failed with "Illegal character ((CTRL-CHAR, code 31))". Let OkHttp manage compression. Adds MistralAIGzipResponseTest, a MockWebServer-based regression test that serves a gzip-encoded chat completion and needs no API key, so it runs in CI (unlike the existing MISTRAL_API_KEY-gated integration tests).
a25c5c4 to
9d94b55
Compare
v1r3n
approved these changes
Jun 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Any LLM task (
LLM_TEXT_COMPLETE,LLM_CHAT_COMPLETE, …) using the Mistral provider always fails with:code 31is0x1F— the first byte of the gzip magic number (0x1F 0x8B). Jackson is being handed a gzip-compressed body that was never decompressed.Root cause
MistralAI#createMistralAiApibuilds theRestClienton anOkHttp3ClientHttpRequestFactoryand additionally sets theAccept-Encodingheader by hand:OkHttp only decompresses a gzip response transparently when it adds the
Accept-Encodingheader itself (via itsBridgeInterceptor). Setting the header explicitly turns that automatic decompression off, so the gzipped body is passed straight to Jackson and parsing fails on the0x1Fbyte.The header was originally added to work around spring-ai#372, but it is unnecessary — and now actively harmful — since the client uses the OkHttp request factory, which handles content encoding on its own.
Fix
Remove the manual
Accept-Encodingheader and let OkHttp manage compression. Mistral responses then decode correctly.Tests
Adds
MistralAIGzipResponseTest, a regression test usingMockWebServerthat serves a gzip-encoded chat completion and asserts it is decoded correctly. It fails against the old code (gzip body reaches Jackson undecoded →code 31) and passes with this change. The test needs no API key, so it runs in CI — unlike the existingMistralAITest.IntegrationTests, which are gated onMISTRAL_API_KEYand therefore skipped in CI (which is why this regression went unnoticed).Impact / scope