Skip to content

Instantly share code, notes, and snippets.

@dinorahto
Created May 1, 2019 17:49
Show Gist options
  • Select an option

  • Save dinorahto/aeee8e13ddec2e957c1222b9c4839b53 to your computer and use it in GitHub Desktop.

Select an option

Save dinorahto/aeee8e13ddec2e957c1222b9c4839b53 to your computer and use it in GitHub Desktop.
Interceptor with Dagger as Singleton
@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