Skip to content

Commit

Permalink
Don't hang on 103
Browse files Browse the repository at this point in the history
  • Loading branch information
yschimke committed Jul 15, 2023
1 parent 0aa953b commit 01170c1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
7 changes: 6 additions & 1 deletion okhttp/src/main/kotlin/okhttp3/internal/http2/Http2Stream.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 01170c1

Please sign in to comment.