From 0d7c58d326cdf2159458f287c83c68185241e644 Mon Sep 17 00:00:00 2001 From: bapeey <90949336+bapeey@users.noreply.github.com> Date: Fri, 3 May 2024 05:31:06 -0500 Subject: [PATCH] RC: Fix webview partially (#2744) * Fix webview * Keep header in apiRequest --- src/en/rizzcomic/build.gradle | 2 +- .../extension/en/rizzcomic/RizzComic.kt | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/en/rizzcomic/build.gradle b/src/en/rizzcomic/build.gradle index d82e142e7..c46552348 100644 --- a/src/en/rizzcomic/build.gradle +++ b/src/en/rizzcomic/build.gradle @@ -3,7 +3,7 @@ ext { extClass = '.RizzComic' themePkg = 'mangathemesia' baseUrl = 'https://rizzfables.com' - overrideVersionCode = 3 + overrideVersionCode = 4 } apply from: "$rootDir/common.gradle" diff --git a/src/en/rizzcomic/src/eu/kanade/tachiyomi/extension/en/rizzcomic/RizzComic.kt b/src/en/rizzcomic/src/eu/kanade/tachiyomi/extension/en/rizzcomic/RizzComic.kt index b06a14b25..510faaeff 100644 --- a/src/en/rizzcomic/src/eu/kanade/tachiyomi/extension/en/rizzcomic/RizzComic.kt +++ b/src/en/rizzcomic/src/eu/kanade/tachiyomi/extension/en/rizzcomic/RizzComic.kt @@ -31,11 +31,24 @@ class RizzComic : MangaThemesiaAlt( override val client = super.client.newBuilder() .rateLimit(1, 3) + .addInterceptor { chain -> + val request = chain.request() + val isApiRequest = request.header("X-API-Request") != null + val headers = request.headers.newBuilder().apply { + if (!isApiRequest) removeAll("X-Requested-With") + removeAll("X-API-Request") + }.build() + chain.proceed(request.newBuilder().headers(headers).build()) + } .build() + override fun headersBuilder() = super.headersBuilder() + .set("X-Requested-With", randomString((1..20).random())) // For WebView + private val apiHeaders by lazy { headersBuilder() .set("X-Requested-With", "XMLHttpRequest") + .set("X-API-Request", "1") .build() } @@ -154,4 +167,9 @@ class RizzComic : MangaThemesiaAlt( it.toString() } } + + private fun randomString(length: Int): String { + val charPool = ('a'..'z') + ('A'..'Z') + return List(length) { charPool.random() }.joinToString("") + } }