Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ internal class DefaultOkHttpClientBuilder @Inject constructor(
}
}
.addNetworkInterceptor(ChuckerInterceptor.Builder(ctx).build())
.addInterceptor(buildRequestIdInterceptor())
.addNetworkInterceptor(buildRequestIdInterceptor())
.addInterceptor(buildDeviceIdInterceptor(deviceId))
.addInterceptor(buildVersionInterceptor(versionName))
.addInterceptor(buildGZipInterceptor())
Expand All @@ -70,10 +70,12 @@ internal class DefaultOkHttpClientBuilder @Inject constructor(
}

private fun buildRequestIdInterceptor() = Interceptor { chain ->
val newRequest = chain.request().newBuilder()
.addHeader(REQUEST_ID_HEADER, UUID.randomUUID().toString())
.build()
return@Interceptor chain.proceed(newRequest)
val requestId = UUID.randomUUID().toString()

// Adding same header to both request and response to
// track the request across network logs and analytics events.
val newRequest = chain.request().newBuilder().addHeader(REQUEST_ID_HEADER, requestId).build()
return@Interceptor chain.proceed(newRequest).newBuilder().addHeader(REQUEST_ID_HEADER, requestId).build()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Smart!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really, but this works. :D IMO, this is a bit of misuse, since the client should not add the response data 🤷🏻

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, but as far as hacks go, this is probably the smallest possible change you could make to make this work 😂 Code golf winner

}

private fun buildAuthenticationInterceptor(authToken: String) = Interceptor { chain ->
Expand Down