in ktor-client/ktor-client-core/common/src/io/ktor/client/features/HttpPlainText.kt [126:148]
override fun install(feature: HttpPlainText, scope: HttpClient) {
scope.requestPipeline.intercept(HttpRequestPipeline.Render) { content ->
feature.addCharsetHeaders(context)
if (content !is String) {
return@intercept
}
val contentType = context.contentType()
if (contentType != null && contentType.contentType != ContentType.Text.Plain.contentType) return@intercept
val contentCharset = contentType?.charset()
proceedWith(feature.wrapContent(content, contentCharset))
}
scope.responsePipeline.intercept(HttpResponsePipeline.Parse) { (info, body) ->
if (info.type != String::class || body !is ByteReadChannel) return@intercept
val bodyBytes = body.readRemaining()
val content = feature.read(context, bodyBytes)
proceedWith(HttpResponseContainer(info, content))
}
}