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:08:19 UTC

[httpcomponents-client] branch 5.0.x 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 5.0.x
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git


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

commit 0010de9c1c43c960dcac788621c635df89f9e4f6
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 80ea417..1f2837c 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.schedule.SchedulingStrategy;
 import org.apache.hc.client5.http.utils.DateUtils;
 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;
@@ -211,10 +212,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);