Created
April 9, 2019 05:34
-
-
Save Unlimity/8001465852b1f5a904f4a2e14be43f5f to your computer and use it in GitHub Desktop.
This file contains 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
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