Skip to content

Commit db817e2

Browse files
Last Sync: 2026-07-08 07:45 (Mobile)
1 parent db75cdb commit db817e2

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

WinbuProvider/src/main/kotlin/com/winbu/CloudflareInterceptor.kt

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,35 @@ import okhttp3.Interceptor
1313
import okhttp3.Response
1414
import java.util.concurrent.atomic.AtomicReference
1515

16-
class CloudflareInterceptor(private val targetCookie: String = "_cc_aud") : Interceptor {
16+
class CloudflareInterceptor(
17+
private val targetCookie: String = "cf_clearance"
18+
) : Interceptor {
1719

1820
@SuppressLint("SetJavaScriptEnabled", "WebViewClientOnReceivedSslError")
1921
override fun intercept(chain: Interceptor.Chain): Response {
2022
val originalRequest = chain.request()
2123
val url = originalRequest.url.toString()
22-
val domainUrl = "${originalRequest.url.scheme}://${originalRequest.url.host}"
24+
val domainUrl = "\( {originalRequest.url.scheme}:// \){originalRequest.url.host}"
2325
val cookieManager = CookieManager.getInstance()
2426

2527
cookieManager.setAcceptCookie(true)
2628

2729
val existingCookies = cookieManager.getCookie(domainUrl) ?: ""
30+
2831
if (existingCookies.contains(targetCookie)) {
2932
val response = chain.proceed(
3033
originalRequest.newBuilder()
3134
.header("Cookie", existingCookies)
3235
.build()
3336
)
34-
if (response.code != 403 && response.code != 503) return response
35-
36-
response.close()
37-
cookieManager.setCookie(domainUrl, "$targetCookie=; Max-Age=0; path=/; Secure")
38-
cookieManager.flush()
37+
38+
if (response.code in listOf(403, 503, 429)) {
39+
response.close()
40+
cookieManager.setCookie(domainUrl, "$targetCookie=; Max-Age=0; path=/; Secure")
41+
cookieManager.flush()
42+
} else {
43+
return response
44+
}
3945
}
4046

4147
val context = CloudStreamApp.context
@@ -57,6 +63,7 @@ class CloudflareInterceptor(private val targetCookie: String = "_cc_aud") : Inte
5763
databaseEnabled = true
5864
loadWithOverviewMode = true
5965
useWideViewPort = true
66+
6067
val ua = userAgentRef.get()
6168
if (ua.isNotBlank()) userAgentString = ua
6269
}
@@ -84,7 +91,7 @@ class CloudflareInterceptor(private val targetCookie: String = "_cc_aud") : Inte
8491
}
8592

8693
var cookieAcquired = false
87-
for (i in 0 until 60) {
94+
for (i in 0 until 45) {
8895
Thread.sleep(1000)
8996
val cookies = cookieManager.getCookie(domainUrl) ?: ""
9097
if (cookies.contains(targetCookie)) {
@@ -111,4 +118,4 @@ class CloudflareInterceptor(private val targetCookie: String = "_cc_aud") : Inte
111118
.build()
112119
)
113120
}
114-
}
121+
}

0 commit comments

Comments
 (0)