|
| 1 | +/* |
| 2 | + * Copyright (C) 2023 Block, Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package okhttp3 |
| 17 | + |
| 18 | +import okhttp3.testing.PlatformRule |
| 19 | +import org.assertj.core.api.Assertions.assertThat |
| 20 | +import org.junit.Ignore |
| 21 | +import org.junit.Rule |
| 22 | +import org.junit.Test |
| 23 | + |
| 24 | +@Ignore("For manual testing only") |
| 25 | +class InformationalResponseCodeTest { |
| 26 | + @JvmField @Rule |
| 27 | + val platform = PlatformRule() |
| 28 | + |
| 29 | + @JvmField @Rule val clientTestRule = OkHttpClientTestRule().apply { |
| 30 | + recordFrames = true |
| 31 | + } |
| 32 | + |
| 33 | + private var client = clientTestRule.newClient() |
| 34 | + |
| 35 | + @Test |
| 36 | + fun test103() { |
| 37 | + // Pretend we are curl so cloudflare will send a 103 |
| 38 | + val request = Request.Builder() |
| 39 | + .url("https://tradingstrategy.ai") |
| 40 | + .header("user-agent", "curl/7.85.0") |
| 41 | + .build() |
| 42 | + |
| 43 | + val response = client.newCall(request).execute() |
| 44 | + |
| 45 | + assertThat(response.code).isEqualTo(200) |
| 46 | + assertThat(response.protocol).isEqualTo(Protocol.HTTP_2) |
| 47 | + response.close() |
| 48 | + |
| 49 | + val outgoingHeaders = ">> 0x00000003\\s+\\d+\\s+HEADERS\\s+END_STREAM\\|END_HEADERS".toRegex() |
| 50 | + assertThat(clientTestRule.eventsList().filter { it.matches(outgoingHeaders) }).hasSize(1) |
| 51 | + |
| 52 | + // Confirm we get the informational response and final response headers. |
| 53 | + val incomingHeaders = "<< 0x00000003\\s+\\d+\\s+HEADERS\\s+END_HEADERS".toRegex() |
| 54 | + assertThat(clientTestRule.eventsList().filter { it.matches(incomingHeaders) }).hasSize(2) |
| 55 | + } |
| 56 | +} |
0 commit comments