in ktor-http/ktor-http-cio/common/src/io/ktor/http/cio/HttpParser.kt [22:54]
public suspend fun parseRequest(input: ByteReadChannel): Request? {
val builder = CharArrayBuilder()
val range = MutableRange(0, 0)
try {
while (true) {
if (!input.readUTF8LineTo(builder, HTTP_LINE_LIMIT)) return null
range.end = builder.length
if (range.start == range.end) continue
val method = parseHttpMethod(builder, range)
val uri = parseUri(builder, range)
val version = parseVersion(builder, range)
skipSpaces(builder, range)
if (range.start != range.end) throw ParserException(
"Extra characters in request line: ${builder.substring(
range.start,
range.end
)}"
)
if (uri.isEmpty()) throw ParserException("URI is not specified")
if (version.isEmpty()) throw ParserException("HTTP version is not specified")
val headers = parseHeaders(input, builder, range) ?: return null
return Request(method, uri, version, headers, builder)
}
} catch (t: Throwable) {
builder.release()
throw t
}
}