You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2021/05/01 16:03:55 UTC

[httpcomponents-client] branch master updated: HTTPCLIENT-2157: response object generated by the classic caching backend is missing the original content encoding

This is an automated email from the ASF dual-hosted git repository.

olegk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git


The following commit(s) were added to refs/heads/master by this push:
     new b151df7  HTTPCLIENT-2157: response object generated by the classic caching backend is missing the original content encoding
b151df7 is described below

commit b151df7e8ccd5dad31193eb8ad7a7f34e14efb07
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Sat May 1 17:26:07 2021 +0200

    HTTPCLIENT-2157: response object generated by the classic caching backend is missing the original content encoding
---
 .../java/org/apache/hc/client5/http/impl/cache/CachingExec.java   | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java
index fa702e0..1198326 100644
--- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java
+++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java
@@ -51,6 +51,7 @@ import org.apache.hc.client5.http.utils.DateUtils;
 import org.apache.hc.core5.function.Factory;
 import org.apache.hc.core5.http.ClassicHttpRequest;
 import org.apache.hc.core5.http.ClassicHttpResponse;
+import org.apache.hc.core5.http.ContentType;
 import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.HttpEntity;
 import org.apache.hc.core5.http.HttpException;
@@ -219,10 +220,13 @@ class CachingExec extends CachingExecBase implements ExecChainHandler {
         response.setVersion(cacheResponse.getVersion() != null ? cacheResponse.getVersion() : HttpVersion.DEFAULT);
         final SimpleBody body = cacheResponse.getBody();
         if (body != null) {
+            final ContentType contentType = body.getContentType();
+            final Header h = response.getFirstHeader(HttpHeaders.CONTENT_ENCODING);
+            final String contentEncoding = h != null ? h.getValue() : null;
             if (body.isText()) {
-                response.setEntity(new StringEntity(body.getBodyText(), body.getContentType()));
+                response.setEntity(new StringEntity(body.getBodyText(), contentType, contentEncoding, false));
             } else {
-                response.setEntity(new ByteArrayEntity(body.getBodyBytes(), body.getContentType()));
+                response.setEntity(new ByteArrayEntity(body.getBodyBytes(), contentType, contentEncoding, false));
             }
         }
         scope.clientContext.setAttribute(HttpCoreContext.HTTP_RESPONSE, response);