in ktor-http/ktor-http-cio/common/src/io/ktor/http/cio/HttpBody.kt [77:113]
public suspend fun parseHttpBody(
contentLength: Long,
transferEncoding: CharSequence?,
connectionOptions: ConnectionOptions?,
input: ByteReadChannel,
out: ByteWriteChannel
) {
if (transferEncoding != null) {
when {
transferEncoding.equalsLowerCase(other = "chunked") -> return decodeChunked(input, out, contentLength)
transferEncoding.equalsLowerCase(other = "identity") -> {
// do nothing special
}
else -> out.close(IllegalStateException("Unsupported transfer-encoding $transferEncoding"))
}
}
if (contentLength != -1L) {
input.copyTo(out, contentLength)
return
}
if (connectionOptions?.close == true) {
input.copyTo(out, Long.MAX_VALUE)
return
}
val cause = IllegalStateException(
"""
Failed to parse request body: request body length should be specified,
chunked transfer encoding should be used or
keep-alive should be disabled (connection: close)
""".trimIndent()
)
out.close(cause)
}