fix(core): adjust OkHttp config

This commit is contained in:
Harsh Shandilya 2023-04-27 18:18:32 +05:30
parent cd05ed4da9
commit 6918cf5f76
No known key found for this signature in database
2 changed files with 15 additions and 3 deletions

View file

@ -71,6 +71,9 @@ interface OkHttpModule {
): OkHttpClient {
return OkHttpClient.Builder()
.apply {
followRedirects(true)
followSslRedirects(true)
retryOnConnectionFailure(true)
cache(cache)
interceptors.forEach(::addNetworkInterceptor)
socketFactory(socketFactory)

View file

@ -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"
}
}