This solution is clearly hacked, but it works.
Suppose you create your Retrofit service as follows:
public <S> S createService(Class<S> serviceClass) {
You will need to add a new CallFactory to your Retrofit instance, so it adds a tag every time. Since the tag will be read-only, we will use an Object array containing only one element, which you can change later.
Retrofit retrofit = retrofitBuilder.client(httpClient).callFactory(new Call.Factory() { @Override public Call newCall(Request request) { request = request.newBuilder().tag(new Object[]{null}).build(); Call call = httpClient.newCall(request);
Now, after making your call, you can change the contents of your tag:
((Object[])call.request().tag())[0] = "hello";
maxoumime
source share