mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-08-18 12:29:15 +02:00
Add an UserAgent Interceptor to Cloudflare Client (#2685)
This commit is contained in:
parent
8e539bebea
commit
bd2dfaad2e
@ -57,17 +57,7 @@ class CloudflareInterceptor(private val context: Context) : Interceptor {
|
|||||||
.firstOrNull { it.name == "cf_clearance" }
|
.firstOrNull { it.name == "cf_clearance" }
|
||||||
resolveWithWebView(originalRequest, oldCookie)
|
resolveWithWebView(originalRequest, oldCookie)
|
||||||
|
|
||||||
// Avoid use empty User-Agent
|
return chain.proceed(originalRequest)
|
||||||
return if (originalRequest.header("User-Agent").isNullOrEmpty()) {
|
|
||||||
val newRequest = originalRequest
|
|
||||||
.newBuilder()
|
|
||||||
.removeHeader("User-Agent")
|
|
||||||
.addHeader("User-Agent", HttpSource.DEFAULT_USERAGENT)
|
|
||||||
.build()
|
|
||||||
chain.proceed(newRequest)
|
|
||||||
} else {
|
|
||||||
chain.proceed(originalRequest)
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
// Because OkHttp's enqueue only handles IOExceptions, wrap the exception so that
|
// Because OkHttp's enqueue only handles IOExceptions, wrap the exception so that
|
||||||
// we don't crash the entire app
|
// we don't crash the entire app
|
||||||
|
@ -19,6 +19,7 @@ class NetworkHelper(context: Context) {
|
|||||||
.build()
|
.build()
|
||||||
|
|
||||||
val cloudflareClient = client.newBuilder()
|
val cloudflareClient = client.newBuilder()
|
||||||
|
.addInterceptor(UserAgentInterceptor())
|
||||||
.addInterceptor(CloudflareInterceptor(context))
|
.addInterceptor(CloudflareInterceptor(context))
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
package eu.kanade.tachiyomi.network
|
||||||
|
|
||||||
|
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||||
|
import okhttp3.Interceptor
|
||||||
|
import okhttp3.Response
|
||||||
|
|
||||||
|
class UserAgentInterceptor : Interceptor {
|
||||||
|
override fun intercept(chain: Interceptor.Chain): Response {
|
||||||
|
val originalRequest = chain.request()
|
||||||
|
|
||||||
|
return if (originalRequest.header("User-Agent").isNullOrEmpty()) {
|
||||||
|
val newRequest = originalRequest
|
||||||
|
.newBuilder()
|
||||||
|
.removeHeader("User-Agent")
|
||||||
|
.addHeader("User-Agent", HttpSource.DEFAULT_USERAGENT)
|
||||||
|
.build()
|
||||||
|
chain.proceed(newRequest)
|
||||||
|
} else {
|
||||||
|
chain.proceed(originalRequest)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user