Package-level declarations
Types
Link copied to clipboard
class CurlLoggingConfig
Link copied to clipboard
Link copied to clipboard
data class MediaApiClient(val timeout: Timeout = Timeout.DEFAULT, val retry: Retry = Retry.DEFAULT) : AutoCloseable
Link copied to clipboard
class MultiPartRes
Functions
Link copied to clipboard
Link copied to clipboard
expect fun httpClient(name: String = "Api Client", timeout: Timeout = Timeout.DEFAULT, retry: Retry = Retry.DEFAULT, httpLogger: KLogger = log, config: HttpClientConfig<*>.() -> Unit = {
install(Resources)
install(ContentNegotiation) { json(json) }
install(ContentEncoding) {
deflate(1.0F)
gzip(0.9F)
}
install(HttpRequestRetry) {
maxRetries = retry.attempts
retryOnException(retryOnTimeout = true)
retryOnServerErrors()
exponentialDelay(maxDelayMs = retry.maxDelay.inWholeMilliseconds)
// modifyRequest { it.headers.append("X_RETRY_COUNT", retryCount.toString()) }
}
install(HttpTimeout) {
connectTimeoutMillis = timeout.connection.inWholeMilliseconds
requestTimeoutMillis = timeout.read.inWholeMilliseconds
socketTimeoutMillis = timeout.write.inWholeMilliseconds
}
install(HttpCookies)
install(Logging) {
level =
when {
httpLogger.isDebugEnabled() -> LogLevel.ALL
httpLogger.isLoggingOff() -> LogLevel.NONE
else -> LogLevel.INFO
}
logger =
object : Logger {
override fun log(message: String) {
httpLogger.info { message }
}
}
format = LoggingFormat.OkHttp
sanitizeHeader { header -> header == HttpHeaders.Authorization }
// filter { it.url.host.contains("localhost").not() }
}
engine {
pipelining = true
// proxy = ProxyBuilder.http()
}
followRedirects = true
install(UserAgent) { agent = "$name-${BuildConfig.version}" }
install(DefaultRequest) {
headers.appendIfNameAndValueAbsent(
HttpHeaders.ContentType, ContentType.Application.Json.toString())
}
install(SSE) {
maxReconnectionAttempts = retry.attempts
reconnectionTime = timeout.connection
}
install(WebSockets) { pingInterval = timeout.read }
expectSuccess = true
HttpResponseValidator {
handleResponseExceptionWithRequest { ex, req ->
val resException = ex as? ResponseException ?: return@handleResponseExceptionWithRequest
val res = resException.response
httpLogger.trace { "Request failed: ${req.method.value} ${req.url} -> ${res.status}" }
}
}
}): HttpClient
Multiplatform HTTP client engine configuration
actual fun httpClient(name: String, timeout: Timeout, retry: Retry, httpLogger: KLogger, config: HttpClientConfig<*>.() -> Unit): HttpClient
actual fun httpClient(name: String, timeout: Timeout, retry: Retry, httpLogger: KLogger, config: HttpClientConfig<*>.() -> Unit): HttpClient
actual fun httpClient(name: String, timeout: Timeout, retry: Retry, httpLogger: KLogger, config: HttpClientConfig<*>.() -> Unit): HttpClient