Support HTTP basic authentication

This commit is contained in:
i-do-cpp 2022-05-01 09:44:58 +02:00
parent f121e297df
commit 057644f592
No known key found for this signature in database
GPG Key ID: F3A348A16AEDE2F3
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 javax.net.ssl.SSLContext
import javax.net.ssl.X509TrustManager
import okhttp3.Credentials
import okhttp3.OkHttpClient
import okhttp3.ResponseBody
import okhttp3.logging.HttpLoggingInterceptor
@ -73,7 +74,19 @@ class SubsonicAPIClient(
.addQueryParameter("c", config.clientID)
.addQueryParameter("f", "json")
.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(proxyPasswordInterceptor)

View File

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