replaceResponse
fun HttpClientCall.replaceResponse(headers: Headers = response.headers, content: HttpResponse.() -> ByteReadChannel): HttpClientCall(source)
Replaces response of the HttpClientCall substituting headers and content. Returns a new HttpClientCall containing this response.
The content function will be called each time the response content is requested. This function should return a new ByteReadChannel instance on each call if the response content should be replayable.
Example usage:
// Content decompression. See ContentEncoding implementation for full example
val decodedCall = originalCall.replaceResponse(
headers = headersOf("Content-Encoding", "identity")
) { // this: HttpResponse ->
decodeGzip(rawContent) // returns a new ByteReadChannel with decoded content
}
Content copied to clipboard