Reputation: 7717
I am using OkHttp 2.3.0 in my Android app. My question is about the transparent GZIP feature. According to the documentation, it should be silently there. But I cannot see the ("accept-encoding", "gzip")
header in the request.
I am using a custom interceptor to add authentication:
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
// 1. sign this request
[get token]
if (!TextUtils.isEmpty(token)) {
// we have a token. let's use it to sign the request
request = request.newBuilder()
.header(AUTH_HEADER_KEY, BEARER_HEADER_VALUE + token)
.build();
}
// 2. proceed with the request
Log.d("t", "Headers " + request.headers()); <--- no gzip header here
Response response = chain.proceed(request);
The log statement only shows the header I have added:
Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxxx
but nothing about GZIP encoding. Should I do something else, or maybe the header is added after I invoke chain.proceed(request)
?
Upvotes: 0
Views: 1403
Reputation: 1237
I was not able to log any OkHttp transparent headers from the app itself. Some people recommend using Charles proxy client, which is probably good way to analyze network traffic, although I found it tricky to make proper configuration, and from version 4 it's not a free tool anymore. For my purpose though, I found it very useful to use network profiler, built into Android Studio (tested on Arctic Fox 2020.3.1).
You may see from below example, that Accept-Encoding
header is available in request, - this header has been added automatically, I have not added it in my app.
Upvotes: 0
Reputation: 40623
The header is added after chain.proceed()
. You can see it by using a network interceptor instead of an application interceptor; see the OkHttp interceptors doc for a comparison of the two.
Upvotes: 1