Skip to content

Instantly share code, notes, and snippets.

@Unlimity
Created April 9, 2019 05:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Unlimity/8001465852b1f5a904f4a2e14be43f5f to your computer and use it in GitHub Desktop.
Save Unlimity/8001465852b1f5a904f4a2e14be43f5f to your computer and use it in GitHub Desktop.
class RetryCallEnqueueOnSubscribe<T>(
private val originalCall: Call<T>
) : OnSubscribe<Response<T>> {
private var retries = 0
override fun call(subscriber: Subscriber<in Response<T>>) {
val call = originalCall.clone()
val headers = call.request()
.headers()
.newBuilder()
.set(RETRY_HEADER, retries++)
.build()
// Dirty hack
Request::class.java.getDeclaredField(HEADERS_FIELD).apply {
isAccessible = true
set(call.request(), headers)
isAccessible = false
}
call.enqueue(...)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment