Merge pull request #1147 from unclejay80/http_proxy_init

added network proxy configuration
This commit is contained in:
Benoit Marty 2020-05-25 23:43:11 +02:00 committed by GitHub
commit 3d33018ffa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 3 deletions

View file

@ -22,7 +22,7 @@ Translations 🗣:
- -
SDK API changes ⚠️: SDK API changes ⚠️:
- - initialize with proxy configuration
Build 🧱: Build 🧱:
- -

View file

@ -23,6 +23,7 @@ import androidx.work.WorkManager
import com.zhuinden.monarchy.Monarchy import com.zhuinden.monarchy.Monarchy
import im.vector.matrix.android.BuildConfig import im.vector.matrix.android.BuildConfig
import im.vector.matrix.android.api.auth.AuthenticationService import im.vector.matrix.android.api.auth.AuthenticationService
import im.vector.matrix.android.api.config.ProxyConfiguration
import im.vector.matrix.android.api.crypto.MXCryptoConfig import im.vector.matrix.android.api.crypto.MXCryptoConfig
import im.vector.matrix.android.internal.SessionManager import im.vector.matrix.android.internal.SessionManager
import im.vector.matrix.android.internal.crypto.attachments.ElementToDecrypt import im.vector.matrix.android.internal.crypto.attachments.ElementToDecrypt
@ -38,7 +39,8 @@ import javax.inject.Inject
data class MatrixConfiguration( data class MatrixConfiguration(
val applicationFlavor: String = "Default-application-flavor", val applicationFlavor: String = "Default-application-flavor",
val cryptoConfig: MXCryptoConfig = MXCryptoConfig() val cryptoConfig: MXCryptoConfig = MXCryptoConfig(),
val proxyConfig: ProxyConfiguration? = null
) { ) {
interface Provider { interface Provider {

View file

@ -0,0 +1,24 @@
/*
* Copyright (c) 2020 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package im.vector.matrix.android.api.config
import java.net.Proxy
/**
* This is the configuration to use a proxy to connect to the matrix servers
*/
data class ProxyConfiguration(val hostname: String, val port: Int, val proxyType: Proxy.Type)

View file

@ -21,6 +21,7 @@ import com.squareup.moshi.Moshi
import dagger.Module import dagger.Module
import dagger.Provides import dagger.Provides
import im.vector.matrix.android.BuildConfig import im.vector.matrix.android.BuildConfig
import im.vector.matrix.android.api.MatrixConfiguration
import im.vector.matrix.android.internal.network.TimeOutInterceptor import im.vector.matrix.android.internal.network.TimeOutInterceptor
import im.vector.matrix.android.internal.network.UserAgentInterceptor import im.vector.matrix.android.internal.network.UserAgentInterceptor
import im.vector.matrix.android.internal.network.interceptors.CurlLoggingInterceptor import im.vector.matrix.android.internal.network.interceptors.CurlLoggingInterceptor
@ -28,6 +29,8 @@ import im.vector.matrix.android.internal.network.interceptors.FormattedJsonHttpL
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor import okhttp3.logging.HttpLoggingInterceptor
import okreplay.OkReplayInterceptor import okreplay.OkReplayInterceptor
import java.net.InetSocketAddress
import java.net.Proxy
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
@Module @Module
@ -64,7 +67,8 @@ internal object NetworkModule {
@Provides @Provides
@JvmStatic @JvmStatic
@Unauthenticated @Unauthenticated
fun providesOkHttpClient(stethoInterceptor: StethoInterceptor, fun providesOkHttpClient(matrixConfiguration: MatrixConfiguration,
stethoInterceptor: StethoInterceptor,
timeoutInterceptor: TimeOutInterceptor, timeoutInterceptor: TimeOutInterceptor,
userAgentInterceptor: UserAgentInterceptor, userAgentInterceptor: UserAgentInterceptor,
httpLoggingInterceptor: HttpLoggingInterceptor, httpLoggingInterceptor: HttpLoggingInterceptor,
@ -82,6 +86,9 @@ internal object NetworkModule {
if (BuildConfig.LOG_PRIVATE_DATA) { if (BuildConfig.LOG_PRIVATE_DATA) {
addInterceptor(curlLoggingInterceptor) addInterceptor(curlLoggingInterceptor)
} }
matrixConfiguration.proxyConfig?.let {
proxy(Proxy(it.proxyType, InetSocketAddress(it.hostname, it.port)))
}
} }
.addInterceptor(okReplayInterceptor) .addInterceptor(okReplayInterceptor)
.build() .build()