From 394abfe450866d4d95f865a80112100f44698471 Mon Sep 17 00:00:00 2001 From: Wszl Date: Sun, 2 Jun 2019 11:35:03 +0800 Subject: [PATCH] fixed can't proxy when use username and password --- .../org/mariotaku/twidere/util/HttpClientFactory.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/util/HttpClientFactory.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/util/HttpClientFactory.kt index ea1764082..6b44d5b72 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/util/HttpClientFactory.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/util/HttpClientFactory.kt @@ -228,7 +228,16 @@ object HttpClientFactory { } val address = InetSocketAddress.createUnresolved(proxyHost, proxyPort) builder.proxy(Proxy(Proxy.Type.HTTP, address)) - + builder.proxyAuthenticator { _, response -> + val b = response.request().newBuilder() + if (response.code() == 407) { + if (username != null && password != null) { + val credential = Credentials.basic(username, password) + b.header("Proxy-Authorization", credential) + } + } + b.build() + } builder.authenticator { _, response -> val b = response.request().newBuilder() if (response.code() == 407) {