From 01170c151958ebb93cc54139648330686748d8f4 Mon Sep 17 00:00:00 2001 From: Yuri Schimke Date: Sat, 15 Jul 2023 12:04:09 +0100 Subject: [PATCH] Don't hang on 103 --- .../internal/http/CallServerInterceptor.kt | 20 ++++++++++--------- .../okhttp3/internal/http2/Http2Stream.kt | 7 ++++++- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/okhttp/src/main/kotlin/okhttp3/internal/http/CallServerInterceptor.kt b/okhttp/src/main/kotlin/okhttp3/internal/http/CallServerInterceptor.kt index 32c21282da01..60161e921c85 100644 --- a/okhttp/src/main/kotlin/okhttp3/internal/http/CallServerInterceptor.kt +++ b/okhttp/src/main/kotlin/okhttp3/internal/http/CallServerInterceptor.kt @@ -148,16 +148,18 @@ class CallServerInterceptor(private val forWebSocket: Boolean) : Interceptor { } } - private fun shouldIgnoreAndWaitForRealResponse(code: Int): Boolean = when { - // Server sent a 100-continue even though we did not request one. Try again to read the - // actual response status. - code == 100 -> true + companion object { + fun shouldIgnoreAndWaitForRealResponse(code: Int): Boolean = when { + // Server sent a 100-continue even though we did not request one. Try again to read the + // actual response status. + code == 100 -> true - // Handle Processing (102) & Early Hints (103) and any new codes without failing - // 100 and 101 are the exceptions with different meanings - // But Early Hints not currently exposed - code in (102 until 200) -> true + // Handle Processing (102) & Early Hints (103) and any new codes without failing + // 100 and 101 are the exceptions with different meanings + // But Early Hints not currently exposed + code in (102 until 200) -> true - else -> false + else -> false + } } } diff --git a/okhttp/src/main/kotlin/okhttp3/internal/http2/Http2Stream.kt b/okhttp/src/main/kotlin/okhttp3/internal/http2/Http2Stream.kt index e8a6d7499d10..1ec8f4ee7c0b 100644 --- a/okhttp/src/main/kotlin/okhttp3/internal/http2/Http2Stream.kt +++ b/okhttp/src/main/kotlin/okhttp3/internal/http2/Http2Stream.kt @@ -18,6 +18,8 @@ package okhttp3.internal.http2 import okhttp3.Headers import okhttp3.internal.EMPTY_HEADERS import okhttp3.internal.assertThreadDoesntHoldLock +import okhttp3.internal.http.CallServerInterceptor +import okhttp3.internal.http.CallServerInterceptor.Companion.shouldIgnoreAndWaitForRealResponse import okhttp3.internal.notifyAll import okhttp3.internal.toHeaderList import okhttp3.internal.wait @@ -283,7 +285,10 @@ class Http2Stream internal constructor( val open: Boolean synchronized(this) { if (!hasResponseHeaders || !inFinished) { - hasResponseHeaders = true + val status = headers[Header.RESPONSE_STATUS_UTF8]?.toIntOrNull() + if (status == null || !shouldIgnoreAndWaitForRealResponse(status)) { + hasResponseHeaders = true + } headersQueue += headers } else { this.source.trailers = headers