diff --git a/okhttp/src/commonJvmAndroid/kotlin/okhttp3/internal/http1/HeadersReader.kt b/okhttp/src/commonJvmAndroid/kotlin/okhttp3/internal/http1/HeadersReader.kt index 58595534124a..38ac13091e46 100644 --- a/okhttp/src/commonJvmAndroid/kotlin/okhttp3/internal/http1/HeadersReader.kt +++ b/okhttp/src/commonJvmAndroid/kotlin/okhttp3/internal/http1/HeadersReader.kt @@ -15,6 +15,8 @@ */ package okhttp3.internal.http1 +import java.io.EOFException +import java.net.ProtocolException import okhttp3.Headers import okio.BufferedSource @@ -28,7 +30,15 @@ class HeadersReader( /** Read a single line counted against the header size limit. */ fun readLine(): String { - val line = source.readUtf8LineStrict(headerLimit) + val line = + try { + source.readUtf8LineStrict(headerLimit) + } catch (e: EOFException) { + throw ProtocolException( + "Header line limit exceeded (${HEADER_LIMIT / 1024} KiB). " + + "The response headers are too large.", + ).initCause(e) + } headerLimit -= line.length.toLong() return line }