Merge pull request #737 from i-do-cpp/develop

Support HTTP basic authentication
This commit is contained in:
Nite 2022-05-17 17:49:07 +02:00 committed by GitHub
commit d9e4b8b3d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View File

@ -8,6 +8,7 @@ import java.security.cert.X509Certificate
import java.util.concurrent.TimeUnit.MILLISECONDS import java.util.concurrent.TimeUnit.MILLISECONDS
import javax.net.ssl.SSLContext import javax.net.ssl.SSLContext
import javax.net.ssl.X509TrustManager import javax.net.ssl.X509TrustManager
import okhttp3.Credentials
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import okhttp3.ResponseBody import okhttp3.ResponseBody
import okhttp3.logging.HttpLoggingInterceptor import okhttp3.logging.HttpLoggingInterceptor
@ -73,7 +74,19 @@ class SubsonicAPIClient(
.addQueryParameter("c", config.clientID) .addQueryParameter("c", config.clientID)
.addQueryParameter("f", "json") .addQueryParameter("f", "json")
.build() .build()
chain.proceed(originalRequest.newBuilder().url(newUrl).build()) val newRequestBuilder = originalRequest.newBuilder().url(newUrl)
if (originalRequest.url.username.isNotEmpty() &&
originalRequest.url.password.isNotEmpty()
) {
newRequestBuilder.addHeader(
"Authorization",
Credentials.basic(
originalRequest.url.username,
originalRequest.url.password
)
)
}
chain.proceed(newRequestBuilder.build())
} }
.addInterceptor(versionInterceptor) .addInterceptor(versionInterceptor)
.addInterceptor(proxyPasswordInterceptor) .addInterceptor(proxyPasswordInterceptor)

View File

@ -298,7 +298,6 @@ class EditServerFragment : Fragment(), OnBackPressedHandler {
url = URL(urlString) url = URL(urlString)
if ( if (
urlString != urlString.trim(' ') || urlString != urlString.trim(' ') ||
urlString.contains("@") ||
url.host.isNullOrBlank() url.host.isNullOrBlank()
) { ) {
throw MalformedURLException() throw MalformedURLException()