Skip to content

Instantly share code, notes, and snippets.

@hkhc
Created April 30, 2020 12:12
Show Gist options
  • Save hkhc/3bc61eef6cb6f193a11ba179d774032e to your computer and use it in GitHub Desktop.
Save hkhc/3bc61eef6cb6f193a11ba179d774032e to your computer and use it in GitHub Desktop.
fun OkHttpClient.Builder.cleanupInterceptor() {
var foundLogger: Interceptor? = null
with(interceptors()) {
val newList = asSequence()
.filter {
if (it is HttpLoggingInterceptor) {
foundLogger = it
false
} else {
true
}
}
.toList()
clear()
addAll(newList)
}
if (foundLogger != null) {
addNetworkInterceptor(foundLogger!!)
}
}
fun OkHttpClient.Builder.buildFinal(): OkHttpClient {
cleanUpcleanupInterceptor()
return build()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment