mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
add prevent option in CloudflareKiller
This commit is contained in:
parent
3c152e04d1
commit
4da165e929
1 changed files with 15 additions and 6 deletions
|
@ -17,6 +17,8 @@ import java.net.URI
|
||||||
class CloudflareKiller : Interceptor {
|
class CloudflareKiller : Interceptor {
|
||||||
companion object {
|
companion object {
|
||||||
const val TAG = "CloudflareKiller"
|
const val TAG = "CloudflareKiller"
|
||||||
|
private val ERROR_CODES = listOf(403, 503)
|
||||||
|
private val CLOUDFLARE_SERVERS = listOf("cloudflare-nginx", "cloudflare")
|
||||||
fun parseCookieMap(cookie: String): Map<String, String> {
|
fun parseCookieMap(cookie: String): Map<String, String> {
|
||||||
return cookie.split(";").associate {
|
return cookie.split(";").associate {
|
||||||
val split = it.split("=")
|
val split = it.split("=")
|
||||||
|
@ -48,15 +50,22 @@ class CloudflareKiller : Interceptor {
|
||||||
|
|
||||||
override fun intercept(chain: Interceptor.Chain): Response = runBlocking {
|
override fun intercept(chain: Interceptor.Chain): Response = runBlocking {
|
||||||
val request = chain.request()
|
val request = chain.request()
|
||||||
|
val response = chain.proceed(request)
|
||||||
val cookies = savedCookies[request.url.host]
|
val cookies = savedCookies[request.url.host]
|
||||||
|
|
||||||
if (cookies == null) {
|
when {
|
||||||
bypassCloudflare(request)?.let {
|
!(response.header("Server") in CLOUDFLARE_SERVERS && response.code in ERROR_CODES) -> {
|
||||||
Log.d(TAG, "Succeeded bypassing cloudflare: ${request.url}")
|
return@runBlocking response
|
||||||
return@runBlocking it
|
}
|
||||||
|
cookies == null -> {
|
||||||
|
bypassCloudflare(request)?.let {
|
||||||
|
Log.d(TAG, "Succeeded bypassing cloudflare: ${request.url}")
|
||||||
|
return@runBlocking it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
return@runBlocking proceed(request, cookies)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return@runBlocking proceed(request, cookies)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
debugWarning({ true }) { "Failed cloudflare at: ${request.url}" }
|
debugWarning({ true }) { "Failed cloudflare at: ${request.url}" }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue