Tentative self signed ssl support #141
@ -35,63 +35,59 @@ import kotlinx.serialization.json.Json
|
||||
|
||||
expect fun setupInsecureHTTPEngine(config: CIOEngineConfig)
|
||||
|
||||
fun createHttpClient(
|
||||
appSettingsService: AppSettingsService,
|
||||
|
||||
api: SelfossApi
|
||||
) =
|
||||
HttpClient(CIO) {
|
||||
if (appSettingsService.getSelfSigned()) {
|
||||
engine {
|
||||
setupInsecureHTTPEngine(this)
|
||||
}
|
||||
}
|
||||
install(ContentNegotiation) {
|
||||
install(HttpCache)
|
||||
json(Json {
|
||||
prettyPrint = true
|
||||
isLenient = true
|
||||
ignoreUnknownKeys = true
|
||||
})
|
||||
}
|
||||
install(Logging) {
|
||||
logger = object : Logger {
|
||||
override fun log(message: String) {
|
||||
Napier.d(message, tag = "LogApiCalls")
|
||||
}
|
||||
}
|
||||
level = LogLevel.INFO
|
||||
}
|
||||
install(HttpTimeout) {
|
||||
requestTimeoutMillis = appSettingsService.getApiTimeout()
|
||||
}
|
||||
install(HttpCookies)
|
||||
install(HttpRequestRetry) {
|
||||
maxRetries = 2
|
||||
retryIf { _, response ->
|
||||
response.status == HttpStatusCode.Forbidden && api.shouldHavePostLogin() && api.hasLoginInfo()
|
||||
}
|
||||
modifyRequest {
|
||||
Napier.i("Will modify", tag = "HttpSend")
|
||||
CoroutineScope(Dispatchers.Main).launch {
|
||||
Napier.i("Will login", tag = "HttpSend")
|
||||
api.login()
|
||||
Napier.i("Did login", tag = "HttpSend")
|
||||
}
|
||||
}
|
||||
}
|
||||
expectSuccess = false
|
||||
}
|
||||
|
||||
class SelfossApi(private val appSettingsService: AppSettingsService) {
|
||||
|
||||
var client = createHttpClient(appSettingsService, this)
|
||||
var client = createHttpClient()
|
||||
AmineB
commented
Why is this needed ? Can't it be replaced by Why is this needed ? Can't it be replaced by `this` ?
|
||||
fun createHttpClient() =
|
||||
HttpClient(CIO) {
|
||||
if (appSettingsService.getSelfSigned()) {
|
||||
engine {
|
||||
setupInsecureHTTPEngine(this)
|
||||
}
|
||||
}
|
||||
install(ContentNegotiation) {
|
||||
install(HttpCache)
|
||||
json(Json {
|
||||
prettyPrint = true
|
||||
isLenient = true
|
||||
ignoreUnknownKeys = true
|
||||
})
|
||||
}
|
||||
install(Logging) {
|
||||
logger = object : Logger {
|
||||
override fun log(message: String) {
|
||||
Napier.d(message, tag = "LogApiCalls")
|
||||
}
|
||||
}
|
||||
level = LogLevel.INFO
|
||||
}
|
||||
install(HttpTimeout) {
|
||||
requestTimeoutMillis = appSettingsService.getApiTimeout()
|
||||
}
|
||||
install(HttpCookies)
|
||||
install(HttpRequestRetry) {
|
||||
maxRetries = 2
|
||||
retryIf { _, response ->
|
||||
response.status == HttpStatusCode.Forbidden && shouldHavePostLogin() && hasLoginInfo()
|
||||
}
|
||||
modifyRequest {
|
||||
Napier.i("Will modify", tag = "HttpSend")
|
||||
CoroutineScope(Dispatchers.Main).launch {
|
||||
Napier.i("Will login", tag = "HttpSend")
|
||||
login()
|
||||
Napier.i("Did login", tag = "HttpSend")
|
||||
}
|
||||
}
|
||||
}
|
||||
expectSuccess = false
|
||||
}
|
||||
|
||||
fun url(path: String) =
|
||||
"${appSettingsService.getBaseUrl()}$path"
|
||||
|
||||
fun refreshLoginInformation() {
|
||||
appSettingsService.refreshApiSettings()
|
||||
client = createHttpClient(appSettingsService, this)
|
||||
client = createHttpClient()
|
||||
}
|
||||
|
||||
fun constructBasicAuthValue(credentials: BasicAuthCredentials): String {
|
||||
|
Loading…
Reference in New Issue
Block a user
Why was this removed ?