Skip to content

Commit

Permalink
Improve readability of the intercept function
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonycr committed Apr 8, 2021
1 parent 5833ae6 commit dc14643
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ import okhttp3.Response
* @param userAgent The user agent that should be sent with every request.
*/
class UserAgentHeaderInterceptor(private val userAgent: String) : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response = chain.proceed(chain.request().run {
newBuilder().headers(headers().newBuilder().addUnsafeNonAscii(HEADER_USER_AGENT, userAgent).build()).build()
override fun intercept(chain: Interceptor.Chain): Response = chain.proceed(chain.request().let { request ->
val updatedHeaders = request.headers().newBuilder().addUnsafeNonAscii(HEADER_USER_AGENT, userAgent).build()

request.newBuilder().headers(updatedHeaders).build()
})

companion object {
Expand Down

0 comments on commit dc14643

Please sign in to comment.