All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.firefly.kotlin.ext.http.HttpClientExtension.kt Maven / Gradle / Ivy

There is a newer version: 5.0.0-dev6
Show newest version
package com.firefly.kotlin.ext.http

import com.firefly.client.http2.SimpleHTTPClient
import com.firefly.client.http2.SimpleResponse
import com.firefly.codec.http2.model.HttpFields
import com.firefly.kotlin.ext.common.Json
import kotlinx.coroutines.experimental.future.await
import kotlinx.coroutines.experimental.withTimeout
import java.util.concurrent.TimeUnit

/**
 * Firefly HTTP client extensions
 *
 * @author Pengtao Qiu
 */

inline fun  SimpleResponse.getJsonBody(charset: String): T = Json.parse(getStringBody(charset))

inline fun  SimpleResponse.getJsonBody(): T = Json.parse(stringBody)

suspend fun SimpleHTTPClient.RequestBuilder.asyncSubmit(
    time: Long = 60 * 1000L,
    unit: TimeUnit = TimeUnit.MILLISECONDS
                                                       ): SimpleResponse = withTimeout(unit.toMillis(time)) { submit().await() }

fun SimpleResponse.getTrailer(): HttpFields = trailerSupplier.get()




© 2015 - 2024 Weber Informatics LLC | Privacy Policy