Hitomi: retry on stream reset error like the website (#6802)
This commit is contained in:
parent
919a6490bb
commit
c3c87863b2
|
@ -1,7 +1,7 @@
|
|||
ext {
|
||||
extName = 'Hitomi'
|
||||
extClass = '.HitomiFactory'
|
||||
extVersionCode = 34
|
||||
extVersionCode = 35
|
||||
isNsfw = true
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.extension.all.hitomi
|
|||
|
||||
import android.app.Application
|
||||
import android.content.SharedPreferences
|
||||
import android.util.Log
|
||||
import androidx.preference.ListPreference
|
||||
import androidx.preference.PreferenceScreen
|
||||
import eu.kanade.tachiyomi.network.GET
|
||||
|
@ -29,6 +30,7 @@ import okhttp3.MediaType.Companion.toMediaType
|
|||
import okhttp3.Request
|
||||
import okhttp3.Response
|
||||
import okhttp3.ResponseBody.Companion.toResponseBody
|
||||
import okhttp3.internal.http2.StreamResetException
|
||||
import rx.Observable
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
|
@ -42,6 +44,7 @@ import java.util.LinkedList
|
|||
import java.util.Locale
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
import kotlin.time.Duration.Companion.seconds
|
||||
|
||||
@OptIn(ExperimentalUnsignedTypes::class)
|
||||
class Hitomi(
|
||||
|
@ -62,7 +65,10 @@ class Hitomi(
|
|||
private val json: Json by injectLazy()
|
||||
|
||||
override val client = network.cloudflareClient.newBuilder()
|
||||
.addInterceptor(::Intercept)
|
||||
.addInterceptor(::jxlContentTypeInterceptor)
|
||||
.apply {
|
||||
interceptors().add(0, ::streamResetRetry)
|
||||
}
|
||||
.build()
|
||||
|
||||
private val preferences: SharedPreferences by lazy {
|
||||
|
@ -708,7 +714,7 @@ class Hitomi(
|
|||
return this.sliceArray(byteArray.indices).contentEquals(byteArray)
|
||||
}
|
||||
|
||||
private fun Intercept(chain: Interceptor.Chain): Response {
|
||||
private fun jxlContentTypeInterceptor(chain: Interceptor.Chain): Response {
|
||||
val response = chain.proceed(chain.request())
|
||||
if (response.headers["Content-Type"] != "application/octet-stream") {
|
||||
return response
|
||||
|
@ -728,6 +734,20 @@ class Hitomi(
|
|||
.build()
|
||||
}
|
||||
|
||||
private fun streamResetRetry(chain: Interceptor.Chain): Response {
|
||||
return try {
|
||||
chain.proceed(chain.request())
|
||||
} catch (e: StreamResetException) {
|
||||
Log.e(name, "reset", e)
|
||||
if (e.message.orEmpty().contains("INTERNAL_ERROR")) {
|
||||
Thread.sleep(2.seconds.inWholeMilliseconds)
|
||||
chain.proceed(chain.request())
|
||||
} else {
|
||||
throw e
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun popularMangaParse(response: Response) = throw UnsupportedOperationException()
|
||||
override fun popularMangaRequest(page: Int) = throw UnsupportedOperationException()
|
||||
override fun latestUpdatesRequest(page: Int) = throw UnsupportedOperationException()
|
||||
|
|
Loading…
Reference in New Issue