mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 05:57:03 +05:30
fix(core): adjust OkHttp config
This commit is contained in:
parent
cd05ed4da9
commit
6918cf5f76
2 changed files with 15 additions and 3 deletions
|
@ -71,6 +71,9 @@ interface OkHttpModule {
|
|||
): OkHttpClient {
|
||||
return OkHttpClient.Builder()
|
||||
.apply {
|
||||
followRedirects(true)
|
||||
followSslRedirects(true)
|
||||
retryOnConnectionFailure(true)
|
||||
cache(cache)
|
||||
interceptors.forEach(::addNetworkInterceptor)
|
||||
socketFactory(socketFactory)
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue