From 82d416ad7f47fb5685f86b845c9df183f7683116 Mon Sep 17 00:00:00 2001 From: antonydp <38143733+antonydp@users.noreply.github.com> Date: Wed, 24 Aug 2022 00:14:07 +0200 Subject: [PATCH] Cloudflare getCookieHeaders (#56) --- .../cloudstream3/network/CloudflareKiller.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/src/main/java/com/lagradost/cloudstream3/network/CloudflareKiller.kt b/app/src/main/java/com/lagradost/cloudstream3/network/CloudflareKiller.kt index ceacb9aa..7dc8dba7 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/network/CloudflareKiller.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/network/CloudflareKiller.kt @@ -9,6 +9,7 @@ import com.lagradost.nicehttp.Requests.Companion.await import com.lagradost.nicehttp.cookies import kotlinx.coroutines.runBlocking import okhttp3.* +import java.net.URI @AnyThread @@ -30,6 +31,17 @@ class CloudflareKiller : Interceptor { val savedCookies: MutableMap> = mutableMapOf() + /** + * Gets the headers with cookies, webview user agent included! + * */ + fun getCookieHeaders(url: String): Headers { + val userAgentHeaders = WebViewResolver.webViewUserAgent?.let { + mapOf("user-agent" to it) + } ?: emptyMap() + + return getHeaders(userAgentHeaders, savedCookies[URI(url).host] ?: emptyMap()) + } + override fun intercept(chain: Interceptor.Chain): Response = runBlocking { val request = chain.request() val cookies = savedCookies[request.url.host]