forked from recloudstream/cloudstream
Cloudflare getCookieHeaders (#56)
This commit is contained in:
parent
92dbbf86b2
commit
82d416ad7f
1 changed files with 12 additions and 0 deletions
|
@ -9,6 +9,7 @@ import com.lagradost.nicehttp.Requests.Companion.await
|
||||||
import com.lagradost.nicehttp.cookies
|
import com.lagradost.nicehttp.cookies
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import okhttp3.*
|
import okhttp3.*
|
||||||
|
import java.net.URI
|
||||||
|
|
||||||
|
|
||||||
@AnyThread
|
@AnyThread
|
||||||
|
@ -30,6 +31,17 @@ class CloudflareKiller : Interceptor {
|
||||||
|
|
||||||
val savedCookies: MutableMap<String, Map<String, String>> = mutableMapOf()
|
val savedCookies: MutableMap<String, Map<String, String>> = 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 {
|
override fun intercept(chain: Interceptor.Chain): Response = runBlocking {
|
||||||
val request = chain.request()
|
val request = chain.request()
|
||||||
val cookies = savedCookies[request.url.host]
|
val cookies = savedCookies[request.url.host]
|
||||||
|
|
Loading…
Reference in a new issue