Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/android-library.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Kaminsky <tobias@kaminsky.me>2022-06-03 10:55:59 +0300
committerGitHub <noreply@github.com>2022-06-03 10:55:59 +0300
commit4821c17184f8f1d595f388cd9c965f7f3fb06b52 (patch)
tree9e8d49f4f2b9a918d0c6a430d2c574f6720ac278
parent5c1b9950a3498edb078a3f9f84e2ce12a44aff36 (diff)
parent41add5d29c43687329923e28ecf0f52b1a30b10c (diff)
Merge pull request #904 from nextcloud/backport/897/stable-2.10rc-2.10.2-012.10.2stable-2.10
[stable-2.10] Bump okhttp to 5.0.0-alpha7 for Happy Eyeballs support
-rw-r--r--library/build.gradle2
-rw-r--r--library/src/main/java/com/nextcloud/common/IPV6PreferringDNS.kt38
-rw-r--r--library/src/main/java/com/nextcloud/common/IPv4FallbackInterceptor.kt76
-rw-r--r--library/src/main/java/com/nextcloud/common/NextcloudClient.kt6
-rw-r--r--library/src/main/java/com/nextcloud/common/PlainClient.kt6
5 files changed, 3 insertions, 125 deletions
diff --git a/library/build.gradle b/library/build.gradle
index ad8d3cac..bda505c6 100644
--- a/library/build.gradle
+++ b/library/build.gradle
@@ -49,7 +49,7 @@ configurations {
dependencies {
implementation 'org.apache.jackrabbit:jackrabbit-webdav:2.13.5'
- api 'com.squareup.okhttp3:okhttp:4.9.3'
+ api 'com.squareup.okhttp3:okhttp:5.0.0-alpha.7'
implementation 'com.gitlab.bitfireAT:dav4jvm:2.1.3' // in transition phase, we use old and new libs
implementation group: 'com.google.code.gson', name: 'gson', version: '2.9.0'
implementation 'androidx.annotation:annotation:1.3.0'
diff --git a/library/src/main/java/com/nextcloud/common/IPV6PreferringDNS.kt b/library/src/main/java/com/nextcloud/common/IPV6PreferringDNS.kt
deleted file mode 100644
index b7622c9d..00000000
--- a/library/src/main/java/com/nextcloud/common/IPV6PreferringDNS.kt
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Nextcloud Android Library is available under MIT license
- *
- * @author Álvaro Brey Vilas
- * Copyright (C) 2022 Álvaro Brey Vilas
- * Copyright (C) 2022 Nextcloud GmbH
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-package com.nextcloud.common
-
-import okhttp3.Dns
-import java.net.InetAddress
-
-object IPV6PreferringDNS : Dns {
-
- override fun lookup(hostname: String): List<InetAddress> {
- return DNSCache.lookup(hostname)
- }
-}
diff --git a/library/src/main/java/com/nextcloud/common/IPv4FallbackInterceptor.kt b/library/src/main/java/com/nextcloud/common/IPv4FallbackInterceptor.kt
deleted file mode 100644
index a41ea05a..00000000
--- a/library/src/main/java/com/nextcloud/common/IPv4FallbackInterceptor.kt
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Nextcloud Android Library is available under MIT license
- *
- * @author Álvaro Brey Vilas
- * Copyright (C) 2022 Álvaro Brey Vilas
- * Copyright (C) 2022 Nextcloud GmbH
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-package com.nextcloud.common
-
-import com.owncloud.android.lib.common.utils.Log_OC
-import okhttp3.ConnectionPool
-import okhttp3.Interceptor
-import okhttp3.Request
-import okhttp3.Response
-import java.net.ConnectException
-import java.net.SocketTimeoutException
-
-class IPv4FallbackInterceptor(private val connectionPool: ConnectionPool) : Interceptor {
- companion object {
- private const val TAG = "IPv4FallbackInterceptor"
- private val SERVER_ERROR_RANGE = 500..599
- }
-
- @Suppress("TooGenericExceptionCaught")
- override fun intercept(chain: Interceptor.Chain): Response {
- val request = chain.request()
- val response = chain.proceed(request)
-
- val hostname = request.url.host
-
- return try {
- if (response.code in SERVER_ERROR_RANGE && DNSCache.isIPV6First(hostname)) {
- Log_OC.d(TAG, "Response error with IPv6, trying IPv4")
- retryWithIPv4(hostname, chain, request)
- } else {
- response
- }
- } catch (e: Exception) {
- if (DNSCache.isIPV6First(hostname) && (e is SocketTimeoutException || e is ConnectException)) {
- return retryWithIPv4(hostname, chain, request)
- }
- throw e
- }
- }
-
- private fun retryWithIPv4(
- hostname: String,
- chain: Interceptor.Chain,
- request: Request
- ): Response {
- Log_OC.d(TAG, "Error with IPv6, trying IPv4")
- DNSCache.setIPVersionPreference(hostname, true)
- connectionPool.evictAll()
- return chain.proceed(request)
- }
-}
diff --git a/library/src/main/java/com/nextcloud/common/NextcloudClient.kt b/library/src/main/java/com/nextcloud/common/NextcloudClient.kt
index 30dca153..722e0c9d 100644
--- a/library/src/main/java/com/nextcloud/common/NextcloudClient.kt
+++ b/library/src/main/java/com/nextcloud/common/NextcloudClient.kt
@@ -40,7 +40,6 @@ import com.owncloud.android.lib.common.network.RedirectionPath
import com.owncloud.android.lib.common.operations.RemoteOperation
import com.owncloud.android.lib.common.operations.RemoteOperationResult
import com.owncloud.android.lib.common.utils.Log_OC
-import okhttp3.ConnectionPool
import okhttp3.CookieJar
import okhttp3.OkHttpClient
import okhttp3.Request
@@ -82,17 +81,14 @@ class NextcloudClient private constructor(
sslContext.init(null, arrayOf<TrustManager>(trustManager), null)
val sslSocketFactory = sslContext.socketFactory
- val connectionPool = ConnectionPool()
return OkHttpClient.Builder()
- .connectionPool(connectionPool)
.cookieJar(CookieJar.NO_COOKIES)
.connectTimeout(DEFAULT_CONNECTION_TIMEOUT_LONG, TimeUnit.MILLISECONDS)
.readTimeout(DEFAULT_DATA_TIMEOUT_LONG, TimeUnit.MILLISECONDS)
.callTimeout(DEFAULT_CONNECTION_TIMEOUT_LONG + DEFAULT_DATA_TIMEOUT_LONG, TimeUnit.MILLISECONDS)
.sslSocketFactory(sslSocketFactory, trustManager)
.hostnameVerifier { _: String?, _: SSLSession? -> true }
- .addNetworkInterceptor(IPv4FallbackInterceptor(connectionPool))
- .dns(IPV6PreferringDNS)
+ .fastFallback(true)
.build()
}
}
diff --git a/library/src/main/java/com/nextcloud/common/PlainClient.kt b/library/src/main/java/com/nextcloud/common/PlainClient.kt
index 2600dcc1..5437ef14 100644
--- a/library/src/main/java/com/nextcloud/common/PlainClient.kt
+++ b/library/src/main/java/com/nextcloud/common/PlainClient.kt
@@ -32,7 +32,6 @@ import android.content.Context
import com.owncloud.android.lib.common.OwnCloudClientFactory.DEFAULT_DATA_TIMEOUT_LONG
import com.owncloud.android.lib.common.network.AdvancedX509TrustManager
import com.owncloud.android.lib.common.network.NetworkUtils
-import okhttp3.ConnectionPool
import okhttp3.CookieJar
import okhttp3.OkHttpClient
import okhttp3.Request
@@ -57,15 +56,12 @@ class PlainClient(context: Context) {
sslContext.init(null, arrayOf<TrustManager>(trustManager), null)
val sslSocketFactory = sslContext.socketFactory
- val connectionPool = ConnectionPool()
return OkHttpClient.Builder()
- .connectionPool(connectionPool)
.cookieJar(CookieJar.NO_COOKIES)
.callTimeout(DEFAULT_DATA_TIMEOUT_LONG, TimeUnit.MILLISECONDS)
.sslSocketFactory(sslSocketFactory, trustManager)
.hostnameVerifier { _: String?, _: SSLSession? -> true }
- .addNetworkInterceptor(IPv4FallbackInterceptor(connectionPool))
- .dns(IPV6PreferringDNS)
+ .fastFallback(true)
.build()
}
}