Skip to content
Permalink
Browse files
HTTPCLIENT-2157: response object generated by the classic caching bac…
…kend is missing the original content encoding
  • Loading branch information
ok2c committed May 1, 2021
1 parent d8d7ad3 commit b151df7e8ccd5dad31193eb8ad7a7f34e14efb07
Showing 1 changed file with 6 additions and 2 deletions.
@@ -51,6 +51,7 @@
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 @@ private static ClassicHttpResponse convert(final SimpleHttpResponse cacheRespons
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);

0 comments on commit b151df7

Please sign in to comment.