Merge branch 'KotatsuApp:master' into patch-1
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package org.koitharu.kotatsu.parsers
|
||||
|
||||
import androidx.annotation.CallSuper
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import okhttp3.Headers
|
||||
import okhttp3.HttpUrl
|
||||
import org.jsoup.nodes.Element
|
||||
@@ -35,8 +34,7 @@ abstract class MangaParser @InternalParsersApi constructor(val source: MangaSour
|
||||
*/
|
||||
protected abstract val configKeyDomain: ConfigKey.Domain
|
||||
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)
|
||||
internal open val headers: Headers? = null
|
||||
open val headers: Headers? = null
|
||||
|
||||
/**
|
||||
* Used as fallback if value of `sortOrder` passed to [getList] is null
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package org.koitharu.kotatsu.parsers.exception
|
||||
|
||||
import okhttp3.Headers
|
||||
import okio.IOException
|
||||
|
||||
class CloudFlareProtectedException(
|
||||
val url: String,
|
||||
val headers: Headers,
|
||||
) : IOException("Protected by CloudFlare: $url")
|
||||
@@ -227,13 +227,13 @@ internal class RemangaParser(
|
||||
return jo.getJSONObject("content").getString("username")
|
||||
}
|
||||
|
||||
private fun getApiHeaders(): Headers? {
|
||||
private fun getApiHeaders(): Headers {
|
||||
val userCookie = context.cookieJar.getCookies(getDomain()).find {
|
||||
it.name == "user"
|
||||
} ?: return null
|
||||
} ?: return headers
|
||||
val jo = JSONObject(URLDecoder.decode(userCookie.value, Charsets.UTF_8.name()))
|
||||
val accessToken = jo.getStringOrNull("access_token") ?: return null
|
||||
return Headers.headersOf("authorization", "bearer $accessToken")
|
||||
val accessToken = jo.getStringOrNull("access_token") ?: return headers
|
||||
return headers.newBuilder().add("authorization", "bearer $accessToken").build()
|
||||
}
|
||||
|
||||
private fun copyCookies() {
|
||||
|
||||
@@ -13,11 +13,15 @@ private const val SERVER_CLOUDFLARE = "cloudflare"
|
||||
class CloudFlareInterceptor : Interceptor {
|
||||
|
||||
override fun intercept(chain: Interceptor.Chain): Response {
|
||||
val response = chain.proceed(chain.request())
|
||||
val request = chain.request()
|
||||
val response = chain.proceed(request)
|
||||
if (response.code == HTTP_FORBIDDEN || response.code == HTTP_UNAVAILABLE) {
|
||||
if (response.header(HEADER_SERVER)?.startsWith(SERVER_CLOUDFLARE) == true) {
|
||||
response.closeQuietly()
|
||||
throw CloudFlareProtectedException(response.request.url.toString())
|
||||
throw CloudFlareProtectedException(
|
||||
url = response.request.url.toString(),
|
||||
headers = request.headers,
|
||||
)
|
||||
}
|
||||
}
|
||||
return response
|
||||
|
||||
Reference in New Issue
Block a user