Created
April 2, 2019 12:32
-
-
Save uzzu/9bbc6451b2578f7d1d525cda47cdde71 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io.ktor.client.HttpClient | |
import io.ktor.client.features.HttpClientFeature | |
import io.ktor.client.response.HttpResponse | |
import io.ktor.client.response.HttpResponseContainer | |
import io.ktor.client.response.HttpResponsePipeline | |
import io.ktor.util.AttributeKey | |
internal class WrappedHttpResponseTransform { | |
companion object Feature : HttpClientFeature<Unit, WrappedHttpResponseTransform> { | |
override val key: AttributeKey<WrappedHttpResponseTransform> = AttributeKey("WrappedHttpResponseTransform") | |
override fun prepare(block: Unit.() -> Unit): WrappedHttpResponseTransform = WrappedHttpResponseTransform() | |
override fun install(feature: WrappedHttpResponseTransform, scope: HttpClient) { | |
scope.responsePipeline.intercept(HttpResponsePipeline.Transform) { (info, response) -> | |
if (response !is HttpResponse) { | |
return@intercept | |
} | |
proceedWith(HttpResponseContainer(info, WrappedHttpResponse(response))) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment