fix: removed content-encoding header to avoid decoding errors #29
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.
httpx
library used byopenai
is sendingAccept-Encoding: gzip, deflate
by default:https://github.com/encode/httpx/blob/7b19cd5f4b749064c6452892a5e58a3758da1d1b/httpx/_client.py#L305-L315
This results in responses from the upstream which are encoded via
gzip
and havingContent-Encoding: gzip
header.In the adapter, all the responses from upstream are decoded, modified and sent to the user as plain text, without any encoding.
Therefore, we must either do the encoding when needed or return the response without
Content-Encoding: gzip
header pretending that the server doesn't support encoding.Given that the latter is so much easier to implement and that the adapter only proxies the response headers for errors, it was chosen as a solution.
How to reproduce the bug
Send an erroneous request to the dial-adapter deployment:
Observe the error message:
resulted from an attempt to decode plain-text content using gzip algorithm since
Content-Encoding
header is set togzip
in the response.