Created
May 1, 2019 17:49
-
-
Save dinorahto/aeee8e13ddec2e957c1222b9c4839b53 to your computer and use it in GitHub Desktop.
Interceptor with Dagger as Singleton
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Provides | |
| @Singleton | |
| fun getUnsafeOkHttpClient(): OkHttpClient { | |
| val interceptor = HttpLoggingInterceptor() | |
| interceptor.level = HttpLoggingInterceptor.Level.BODY | |
| val builder = OkHttpClient.Builder() | |
| builder.addInterceptor(interceptor) | |
| .connectTimeout(30, TimeUnit.SECONDS) | |
| .readTimeout(30, TimeUnit.SECONDS) | |
| .followRedirects(true) | |
| .followSslRedirects(true) | |
| .addInterceptor { chain -> | |
| val newRequest = chain.request().newBuilder() | |
| .addHeader("Authorization", UUID.randomUUID().toString()) | |
| .build() | |
| chain.proceed(newRequest) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment