Created
April 30, 2020 12:12
-
-
Save hkhc/3bc61eef6cb6f193a11ba179d774032e to your computer and use it in GitHub Desktop.
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
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