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 {
|
||||
companion object {
|
||||
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> {
|
||||
return cookie.split(";").associate {
|
||||
val split = it.split("=")
|
||||
|
@ -48,15 +50,22 @@ class CloudflareKiller : Interceptor {
|
|||
|
||||
override fun intercept(chain: Interceptor.Chain): Response = runBlocking {
|
||||
val request = chain.request()
|
||||
val response = chain.proceed(request)
|
||||
val cookies = savedCookies[request.url.host]
|
||||
|
||||
if (cookies == null) {
|
||||
bypassCloudflare(request)?.let {
|
||||
Log.d(TAG, "Succeeded bypassing cloudflare: ${request.url}")
|
||||
return@runBlocking it
|
||||
when {
|
||||
!(response.header("Server") in CLOUDFLARE_SERVERS && response.code in ERROR_CODES) -> {
|
||||
return@runBlocking response
|
||||
}
|
||||
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}" }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue