Fix stale Content-Encoding header in ProxyServlet after HttpClient bump - #7937
Conversation
HttpClient5 5.6+ stopped stripping Content-Encoding/Content-Length after auto-decompressing responses, so ProxyServlet forwarded a decompressed body under a stale compressed-encoding header. Disable auto-decompression so bytes and headers always stay consistent.
…fb_httpClientUpgrade
|
Verifying with RStudio on TeamCity: https://teamcity.labkey.org/buildConfiguration/LabKey_267Release_Premium_ModulesSuites_RStudioPostgres/4134256 |
XingY
left a comment
There was a problem hiding this comment.
It seems our ProxyServlet diverged from the original implementation:
https://github.com/mitre/HTTP-Proxy-Servlet/blame/9a522c5c021e6941cd951941ed49d96ff996f1eb/src/main/java/org/mitre/dsmiley/httpproxy/ProxyServlet.java#L286
Based on the original code, if should check doHandleCompression to set the config.
| if (doHandleCompression && headerName.equals(HttpHeaders.ACCEPT_ENCODING)) | ||
| return; | ||
| // In Apache HttpClient <5.6.4, these headers were automatically removed. Now we need to remove them manually. | ||
| if (doHandleCompression && (headerName.equals(HttpHeaders.CONTENT_ENCODING) || headerName.equals(HttpHeaders.CONTENT_MD5))) |
There was a problem hiding this comment.
Can this be added in LabKeyProxyServlet as override instead? We try to keep ProxyServlet consistent with the original library to make the next sync easier.
There was a problem hiding this comment.
On, sure, that makes sense.
I suspect something similar will be added to the upstream if/when they update HttpClient. They haven't really made any significant changes since 2023.
|
Verifying on TeamCity with latest changes: https://teamcity.labkey.org/buildConfiguration/LabKey_267Release_Premium_ModulesSuites_RStudioPostgres/4137530 |
Rationale
The bug, in ProxyServlet:
Why 5.6.4 breaks this: Apache HttpClient5's internal ContentCompressionExec auto-decompresses gzip/deflate response bodies transparently. In 5.5.2 it also scrubbed the now-stale headers off the raw response:
In 5.6.4 (part of a rewrite adding pluggable codecs — Brotli/Zstd/etc. — via a new ContentCodecRegistry), that cleanup was dropped:
The entity is still silently decompressed, but Content-Encoding: gzip (and the old compressed Content-Length) now survive on the response object and get forwarded verbatim by ProxyServlet.
Net effect: browser receives Content-Encoding: gzip header + already-decompressed plaintext body → Firefox refuses to render it → exactly the contentEncodingError you're seeing.
Related Pull Requests
Changes