diff --git a/src/main/java/no/digipost/api/client/internal/http/response/HttpResponseUtils.java b/src/main/java/no/digipost/api/client/internal/http/response/HttpResponseUtils.java index dd1e1fbf..6034b0dc 100644 --- a/src/main/java/no/digipost/api/client/internal/http/response/HttpResponseUtils.java +++ b/src/main/java/no/digipost/api/client/internal/http/response/HttpResponseUtils.java @@ -23,6 +23,7 @@ import no.digipost.api.client.representations.ErrorType; import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; import org.apache.hc.core5.http.ClassicHttpResponse; +import org.apache.hc.core5.http.Header; import org.apache.hc.core5.http.HttpEntity; import org.apache.hc.core5.http.HttpResponse; import org.apache.hc.core5.http.HttpStatus; @@ -32,6 +33,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; +import java.util.zip.GZIPInputStream; import static no.digipost.api.client.errorhandling.ErrorCode.GENERAL_ERROR; import static no.digipost.api.client.internal.ExceptionUtils.exceptionNameAndMessage; @@ -55,7 +57,14 @@ public static InputStream safelyOfferEntityStreamExternally(ClassicHttpResponse try { checkResponse(response, eventLogger); entity = response.getEntity(); - return entity.getContent(); + InputStream stream = entity.getContent(); + + Header encodingHeader = response.getFirstHeader("Content-Encoding"); + if (encodingHeader != null && "gzip".equalsIgnoreCase(encodingHeader.getValue())) { + return new GZIPInputStream(stream); + } + + return stream; } catch (IOException | RuntimeException e) { try (ClassicHttpResponse autoClosed = response) { EntityUtils.consume(entity);