I\'m trying to process a server response which is GZIP\'d. The response comes with a header
Content-Type: application/x-gzip
but does not
There is a better way than reinventing the wheel. Just add the Content-Encoding
header yourself.
.addNetworkInterceptor((Interceptor.Chain chain) -> {
Request req = chain.request();
Headers.Builder headersBuilder = req.headers().newBuilder();
String credential = Credentials.basic(...);
headersBuilder.set("Authorization", credential);
Response res = chain.proceed(req.newBuilder().headers(headersBuilder.build()).build());
return res.newBuilder()
.header("Content-Encoding", "gzip")
.header("Content-Type", ""application/json")
.build();
})
In fact, your code is a classic example of the evils of using internal code (like com.sun
packages from the JDK). RealResponseBody
doesn't have that constructor anymore.