From c8e3aaa20c28926185600b7f4118ee58697f93f4 Mon Sep 17 00:00:00 2001 From: Osip Fatkullin Date: Wed, 12 Feb 2025 18:32:57 +0100 Subject: [PATCH] Stricter request/response parsing --- .../common/src/io/ktor/http/cio/HttpParser.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ktor-http/ktor-http-cio/common/src/io/ktor/http/cio/HttpParser.kt b/ktor-http/ktor-http-cio/common/src/io/ktor/http/cio/HttpParser.kt index 045f3f9a81f..0104b15d5d0 100644 --- a/ktor-http/ktor-http-cio/common/src/io/ktor/http/cio/HttpParser.kt +++ b/ktor-http/ktor-http-cio/common/src/io/ktor/http/cio/HttpParser.kt @@ -1,6 +1,6 @@ /* -* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. -*/ + * Copyright 2014-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. + */ package io.ktor.http.cio @@ -31,7 +31,7 @@ public suspend fun parseRequest(input: ByteReadChannel): Request? { try { while (true) { - if (!input.readUTF8LineTo(builder, HTTP_LINE_LIMIT)) return null + if (!input.readUTF8LineTo(builder, HTTP_LINE_LIMIT, LineEndingMode.HttpLineEndings)) return null range.end = builder.length if (range.start == range.end) continue @@ -66,7 +66,7 @@ public suspend fun parseResponse(input: ByteReadChannel): Response? { val range = MutableRange(0, 0) try { - if (!input.readUTF8LineTo(builder, HTTP_LINE_LIMIT)) return null + if (!input.readUTF8LineTo(builder, HTTP_LINE_LIMIT, LineEndingMode.HttpLineEndings)) return null range.end = builder.length val version = parseVersion(builder, range) @@ -106,7 +106,7 @@ internal suspend fun parseHeaders( try { while (true) { - if (!input.readUTF8LineTo(builder, HTTP_LINE_LIMIT)) { + if (!input.readUTF8LineTo(builder, HTTP_LINE_LIMIT, LineEndingMode.HttpLineEndings)) { headers.release() return null }