|
31 | 31 | import okhttp3.mockwebserver.MockResponse;
|
32 | 32 | import okhttp3.mockwebserver.SocketPolicy;
|
33 | 33 | import org.junit.jupiter.api.Test;
|
| 34 | +import org.junit.jupiter.api.condition.EnabledIfSystemProperty; |
34 | 35 |
|
35 | 36 | /** Tests client-specific behavior, such as ensuring Content-Length is sent when specified. */
|
36 | 37 | public class DefaultClientTest extends AbstractClientTest {
|
@@ -80,19 +81,41 @@ public void patch() throws Exception {
|
80 | 81 | assertThat(exception).hasCauseInstanceOf(ProtocolException.class);
|
81 | 82 | }
|
82 | 83 |
|
| 84 | + @Test |
83 | 85 | @Override
|
84 | 86 | public void noResponseBodyForPost() throws Exception {
|
85 | 87 | super.noResponseBodyForPost();
|
86 | 88 | MockWebServerAssertions.assertThat(server.takeRequest())
|
87 | 89 | .hasMethod("POST")
|
| 90 | + .hasNoHeaderNamed("Content-Type"); |
| 91 | + } |
| 92 | + |
| 93 | + @Test |
| 94 | + @EnabledIfSystemProperty(named = "sun.net.http.allowRestrictedHeaders", matches = "true") |
| 95 | + public void noRequestBodyForPostWithAllowRestrictedHeaders() throws Exception { |
| 96 | + super.noResponseBodyForPost(); |
| 97 | + MockWebServerAssertions.assertThat(server.takeRequest()) |
| 98 | + .hasMethod("POST") |
| 99 | + .hasNoHeaderNamed("Content-Type") |
88 | 100 | .hasHeaders(entry("Content-Length", Collections.singletonList("0")));
|
89 | 101 | }
|
90 | 102 |
|
| 103 | + @Test |
91 | 104 | @Override
|
92 | 105 | public void noResponseBodyForPut() throws Exception {
|
93 | 106 | super.noResponseBodyForPut();
|
94 | 107 | MockWebServerAssertions.assertThat(server.takeRequest())
|
95 | 108 | .hasMethod("PUT")
|
| 109 | + .hasNoHeaderNamed("Content-Type"); |
| 110 | + } |
| 111 | + |
| 112 | + @Test |
| 113 | + @EnabledIfSystemProperty(named = "sun.net.http.allowRestrictedHeaders", matches = "true") |
| 114 | + public void noResponseBodyForPutWithAllowRestrictedHeaders() throws Exception { |
| 115 | + super.noResponseBodyForPut(); |
| 116 | + MockWebServerAssertions.assertThat(server.takeRequest()) |
| 117 | + .hasMethod("PUT") |
| 118 | + .hasNoHeaderNamed("Content-Type") |
96 | 119 | .hasHeaders(entry("Content-Length", Collections.singletonList("0")));
|
97 | 120 | }
|
98 | 121 |
|
|
0 commit comments