CAMEL-23936: Fix logHttpActivity losing Content-Encoding on gzip responses#24506
Conversation
…onses Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
|
🧪 CI tested the following changed modules:
🔬 Scalpel shadow comparison — Scalpel: 61 tested, 29 compile-only — current: 61 all testedMaveniverse Scalpel detected 90 affected modules (current approach: 61).
|
davsclaus
left a comment
There was a problem hiding this comment.
Clean, well-targeted bug fix. The one-line change at LoggingHttpActivityListener.java:208 correctly preserves the Content-Encoding when re-creating the ByteArrayEntity after logging consumes the entity stream. Without this, ContentCompressionExec skips gzip decompression and downstream processing fails.
The ce variable correctly holds the original content encoding in both request and response paths, and the ByteArrayEntity(byte[], ContentType, String) constructor handles null safely for the non-compressed case.
Test coverage is good — HttpLoggingActivityGzipTest exercises the exact bug scenario with a local gzip-compressing HTTP server.
Minor suggestion (non-blocking): The new test duplicates ~130 lines of server infrastructure (inner interceptor classes and entity wrappers) from HttpCompressionTest. It could extend HttpCompressionTest instead, overriding only createCamelContext() and adding the logging-specific test method. But the current approach is consistent with the self-contained test pattern used elsewhere in the module.
This review was generated by an AI agent (Claude Code on behalf of davsclaus) and may contain inaccuracies. Please verify all suggestions before applying.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
oscerd
left a comment
There was a problem hiding this comment.
Thanks for the fix, Claus — reviewed against main and it looks correct.
- The one-line change in
LoggingHttpActivityListener(new ByteArrayEntity(arr, ct)→new ByteArrayEntity(arr, ct, ce)) correctly re-attaches theContent-Encodingto the re-created entity.arrholds the raw gzip bytes and the separate localdatadecompression used only for logging is untouched, so there is no double-decode and the non-logging path is unaffected (the listener runs only whenlogHttpActivity=true). - Good regression coverage:
HttpLoggingActivityGzipTestextendsHttpCompressionTest, noThread.sleep, and CI is green. - Commit convention and attribution/sign-off trailers are correct.
LGTM.
Reviewed with Claude Code on behalf of Andrea Cosentino. This review was generated by an AI agent and may contain inaccuracies; please verify all suggestions before applying.
…onses Backport of #24506. When logHttpActivity is enabled and the HTTP server returns a gzip-encoded response, the replacement ByteArrayEntity created during logging did not preserve the original Content-Encoding, causing HttpClient to skip decompression. Pass the content encoding to the ByteArrayEntity constructor. Closes #24507 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
Summary
Claude Code on behalf of davsclaus
When
logHttpActivityis enabled and the HTTP server returns a gzip-encoded response, the response body is not decompressed, causing downstream processing (e.g., Jackson JSON parsing) to fail withJsonParseException: Illegal character (CTRL-CHAR, code 31).Root cause: In
LoggingHttpActivityListener, when the response entity's stream is consumed for logging and a replacementByteArrayEntityis created, the originalContent-Encoding(e.g.,gzip) was not passed to the new entity. This caused Apache HttpClient'sContentCompressionExecto skip decompression, leaving the raw gzip bytes in the response body.Fix: Pass the original content encoding as the third argument to the
ByteArrayEntityconstructor, preserving the encoding metadata for downstream decompression.LoggingHttpActivityListener.java:208—new ByteArrayEntity(arr, ct)→new ByteArrayEntity(arr, ct, ce)Test plan
HttpLoggingActivityGzipTestextendsHttpCompressionTest— verifies gzip-encoded responses are correctly decompressed whenlogHttpActivityis enabledHttpCompressionTestalso pass with logging enabled (bonus coverage)camel-httptests pass🤖 Generated with Claude Code
Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com