-
Notifications
You must be signed in to change notification settings - Fork 7.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to add RequestInterceptor in Retrofit 2.0? #1299
Comments
I also tried the following code:
based on this answer: http://stackoverflow.com/questions/33558352/retrofit-2-addqueryparam-replacement But it didn't seem to do anything, and seems that this request with its headers are overridden during the call time of the request. |
After a lot of trials, one thing solved my problem I didn't deep into the code, but what I add HttpLoggingInterceptor before my custom Interceptor, the custom is ignored completely, so I had to flip them, does this make any sense? |
Yes. Interceptors are ordered. An earlier one cannot see what a later one On Wed, Nov 18, 2015, 6:12 PM Mohamed Shehab [email protected]
|
ok, this makes sense then. |
How can I add request interceptor in Retrofit 2.0, I looked at OKHttp but I found that to add request interceptor I have to actually create the request myself and if I create the request and set it in OkHttp how can this be used with Retrofit?
For logging I did that:
But I'm not sure how can I achieve this for the Request in order to add custom headers,
Another question (may be there's a better architecture), I have an API with 5 end-points and I have 1 abstract class where the client is built, then there are 5 different classes each one is based on 1 end-point, and they're all extending the abstract class where the client is constructed, in my old code with Retrofit 1, the abstract class had a request interceptor and is aware of the app's context, and populates the headers dynamically (which includes a checksum for the request, based on the parameters) how can I achieve this without request interceptor? and without have to repeat the headers for each end-point ?
I already looked at this:
https://github.com/square/okhttp/wiki/Interceptors
But I don't get how can add this interceptor without creating the request, and If I created the request myself, how can I pass this to Retrofit? or what's the use of retrofit then?
The text was updated successfully, but these errors were encountered: