Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand 103 handling to other non-specific 1XX messages. #7629

Merged
merged 3 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package okhttp3.internal.http
import java.io.IOException
import java.net.ProtocolException
import okhttp3.Interceptor
import okhttp3.Protocol
import okhttp3.Response
import okhttp3.internal.connection.Exchange
import okhttp3.internal.http2.ConnectionShutdownException
Expand Down Expand Up @@ -153,8 +152,10 @@ class CallServerInterceptor(private val forWebSocket: Boolean) : Interceptor {
// actual response status.
code == 100 -> true

// Early Hints (103) but not supported yet in OkHttp
code == 103 -> 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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ import okhttp3.internal.checkOffsetAndCount
import okhttp3.internal.discard
import okhttp3.internal.headersContentLength
import okhttp3.internal.http.ExchangeCodec
import okhttp3.internal.http.HTTP_CONTINUE
import okhttp3.internal.http.RequestLine
import okhttp3.internal.http.StatusLine
import okhttp3.internal.http.promisesBody
import okhttp3.internal.http.receiveHeaders
import okhttp3.internal.http.HTTP_CONTINUE
import okhttp3.internal.http.HTTP_EARLY_HINTS
import okhttp3.internal.skipAll
import okio.Buffer
import okio.BufferedSink
Expand Down Expand Up @@ -193,8 +192,9 @@ class Http1ExchangeCodec(
state = STATE_READ_RESPONSE_HEADERS
responseBuilder
}
statusLine.code == HTTP_EARLY_HINTS -> {
// Early Hints will mean a second header are coming.
statusLine.code in (102 until 200) -> {
// Processing and Early Hints will mean a second headers are coming.
// Treat others the same for now
state = STATE_READ_RESPONSE_HEADERS
responseBuilder
}
Expand Down
31 changes: 30 additions & 1 deletion okhttp/src/jvmTest/java/okhttp3/CallTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ import okhttp3.internal.DoubleInetAddressDns
import okhttp3.internal.RecordingOkAuthenticator
import okhttp3.internal.addHeaderLenient
import okhttp3.internal.closeQuietly
import okhttp3.internal.http.HTTP_EARLY_HINTS
import okhttp3.internal.http.HTTP_PROCESSING
import okhttp3.internal.http.RecordingProxySelector
import okhttp3.internal.userAgent
import okhttp3.okio.LoggingFilesystem
Expand Down Expand Up @@ -2966,7 +2968,7 @@ open class CallTest {
MockResponse.Builder()
.addInformationalResponse(
MockResponse(
code = 103,
code = HTTP_EARLY_HINTS,
headers = headersOf("Link", "</style.css>; rel=preload; as=style"),
)
).build()
Expand All @@ -2983,6 +2985,33 @@ open class CallTest {
assertThat(recordedRequest.headers["Link"]).isNull()
}

@Test
fun serverRespondsWithProcessingHttp2() {
enableProtocol(Protocol.HTTP_2)
serverRespondsWithProcessing()
}

@Test
fun serverRespondsWithProcessing() {
server.enqueue(
MockResponse.Builder()
.addInformationalResponse(
MockResponse(
code = HTTP_PROCESSING,
)
).build()
)
val request = Request(
url = server.url("/"),
body = "abc".toRequestBody("text/plain".toMediaType()),
)
executeSynchronously(request)
.assertCode(200)
.assertSuccessful()
val recordedRequest = server.takeRequest()
assertThat(recordedRequest.body.readUtf8()).isEqualTo("abc")
}

@Test
fun serverRespondsWithUnsolicited100Continue_HTTP2() {
enableProtocol(Protocol.HTTP_2)
Expand Down