Skip to content
This repository has been archived by the owner on Oct 3, 2022. It is now read-only.

Commit

Permalink
Fix Cloudflare interceptor
Browse files Browse the repository at this point in the history
The solution was to force every request on shosetsu to always have
 the same user agent.
  • Loading branch information
Doomsdayrs committed Aug 29, 2022
1 parent fd2d0c2 commit 289dd65
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import androidx.lifecycle.LifecycleOwner
import androidx.work.Configuration
import app.shosetsu.android.BuildConfig
import app.shosetsu.android.R
import app.shosetsu.android.common.SettingKey
import app.shosetsu.android.common.consts.Notifications
import app.shosetsu.android.common.consts.ShortCuts
import app.shosetsu.android.common.consts.USER_AGENT
import app.shosetsu.android.common.ext.fileOut
import app.shosetsu.android.common.ext.launchIO
import app.shosetsu.android.common.ext.logE
Expand All @@ -25,8 +28,6 @@ import app.shosetsu.android.viewmodel.factory.ViewModelFactory
import app.shosetsu.lib.ShosetsuSharedLib
import app.shosetsu.lib.lua.ShosetsuLuaLib
import app.shosetsu.lib.lua.shosetsuGlobals
import app.shosetsu.android.BuildConfig
import app.shosetsu.android.R
import com.google.android.material.color.DynamicColors
import kotlinx.coroutines.runBlocking
import okhttp3.OkHttpClient
Expand Down Expand Up @@ -204,7 +205,7 @@ class ShosetsuApplication : Application(), LifecycleEventObserver, DIAware,
}

ShosetsuSharedLib.shosetsuHeaders = arrayOf(
"User-Agent" to "Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0"
"User-Agent" to USER_AGENT
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package app.shosetsu.android.common.consts
* You should have received a copy of the GNU General Public License
* along with shosetsu. If not, see <https://www.gnu.org/licenses/>.
*/

const val USER_AGENT = "Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0"

const val SELECTED_STROKE_WIDTH: Int = 8

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package app.shosetsu.android.providers.network

import app.shosetsu.android.common.consts.USER_AGENT
import app.shosetsu.android.common.ext.logI
import app.shosetsu.android.common.utils.CookieJarSync
import okhttp3.OkHttpClient
Expand Down Expand Up @@ -32,7 +33,7 @@ import java.util.logging.Logger
fun createOkHttpClient(): OkHttpClient = OkHttpClient.Builder()
.cookieJar(CookieJarSync)
.addInterceptor {
val r = it.request()
val r = it.request().newBuilder().header("User-Agent", USER_AGENT).build()
it.logI(r.toString())
val response = it.proceed(r)
it.logI(response.toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import android.webkit.CookieManager
import android.webkit.WebView
import android.webkit.WebViewClient
import androidx.appcompat.app.AppCompatActivity
import app.shosetsu.android.R
import app.shosetsu.android.activity.MainActivity
import app.shosetsu.android.common.consts.BundleKeys.BUNDLE_URL
import app.shosetsu.android.common.consts.USER_AGENT
import app.shosetsu.android.common.ext.launchUI
import app.shosetsu.android.common.ext.logI
import app.shosetsu.android.common.ext.logV
import app.shosetsu.android.common.ext.openInBrowser
import app.shosetsu.android.common.utils.CookieJarSync
import app.shosetsu.android.R
import app.shosetsu.android.databinding.ActivityWebviewBinding
import app.shosetsu.android.databinding.ActivityWebviewBinding.inflate
import okhttp3.Cookie
Expand Down Expand Up @@ -95,6 +96,7 @@ class WebViewApp : AppCompatActivity(), DIAware {
setDisplayHomeAsUpEnabled(true)
}

binding.webview.settings.userAgentString = USER_AGENT
binding.webview.settings.javaScriptEnabled = true
CookieManager.getInstance().setAcceptThirdPartyCookies(binding.webview, true)

Expand Down

0 comments on commit 289dd65

Please sign in to comment.