diff --git a/core/src/main/kotlin/dev/msfjarvis/claw/core/injection/OkHttpModule.kt b/core/src/main/kotlin/dev/msfjarvis/claw/core/injection/OkHttpModule.kt index 3910720f..450a4188 100644 --- a/core/src/main/kotlin/dev/msfjarvis/claw/core/injection/OkHttpModule.kt +++ b/core/src/main/kotlin/dev/msfjarvis/claw/core/injection/OkHttpModule.kt @@ -71,6 +71,9 @@ interface OkHttpModule { ): OkHttpClient { return OkHttpClient.Builder() .apply { + followRedirects(true) + followSslRedirects(true) + retryOnConnectionFailure(true) cache(cache) interceptors.forEach(::addNetworkInterceptor) socketFactory(socketFactory) diff --git a/core/src/main/kotlin/dev/msfjarvis/claw/core/network/UserAgentInterceptor.kt b/core/src/main/kotlin/dev/msfjarvis/claw/core/network/UserAgentInterceptor.kt index 3468561c..19569ed8 100644 --- a/core/src/main/kotlin/dev/msfjarvis/claw/core/network/UserAgentInterceptor.kt +++ b/core/src/main/kotlin/dev/msfjarvis/claw/core/network/UserAgentInterceptor.kt @@ -1,5 +1,5 @@ /* - * Copyright © 2022 Harsh Shandilya. + * Copyright © 2022-2023 Harsh Shandilya. * Use of this source code is governed by an MIT-style * license that can be found in the LICENSE file or at * https://opensource.org/licenses/MIT. @@ -10,9 +10,18 @@ import javax.inject.Inject import okhttp3.Interceptor import okhttp3.Response -/** An OkHttp [Interceptor] that adds a recognizable User-Agent header to all network requests. */ +/** An OkHttp [Interceptor] that feigns a browser User-Agent for all requests. */ class UserAgentInterceptor @Inject constructor() : Interceptor { override fun intercept(chain: Interceptor.Chain): Response { - return chain.proceed(chain.request().newBuilder().header("User-Agent", "Claw-Android").build()) + return chain.proceed( + chain.request().newBuilder().header("User-Agent", CHROME_USER_AGENT).build() + ) + } + + private companion object { + private const val DEFAULT_BROWSER_VERSION = "100.0.0.0" + private const val CHROME_USER_AGENT = + "Mozilla/5.0 (Linux; Android 11; Build/RQ2A.210505.003) AppleWebKit/537.36 " + + "(KHTML, like Gecko) Version/4.0 Chrome/$DEFAULT_BROWSER_VERSION Mobile Safari/537.36" } }