Tests client-specific behavior, such as ensuring Content-Length is sent when specified.
| 36 | |
| 37 | /** Tests client-specific behavior, such as ensuring Content-Length is sent when specified. */ |
| 38 | public class DefaultClientTest extends AbstractClientTest { |
| 39 | |
| 40 | protected Client disableHostnameVerification = |
| 41 | new DefaultClient(TrustingSSLSocketFactory.get(), (_, _) -> true); |
| 42 | |
| 43 | @Override |
| 44 | public Builder newBuilder() { |
| 45 | return Feign.builder().client(new DefaultClient(TrustingSSLSocketFactory.get(), null, false)); |
| 46 | } |
| 47 | |
| 48 | @Test |
| 49 | void retriesFailedHandshake() throws IOException, InterruptedException { |
| 50 | server.useHttps(TrustingSSLSocketFactory.get("localhost"), false); |
| 51 | server.enqueue(new MockResponse().setSocketPolicy(SocketPolicy.FAIL_HANDSHAKE)); |
| 52 | server.enqueue(new MockResponse()); |
| 53 | |
| 54 | TestInterface api = |
| 55 | newBuilder().target(TestInterface.class, "https://localhost:" + server.getPort()); |
| 56 | |
| 57 | api.post("foo"); |
| 58 | assertThat(server.getRequestCount()).isEqualTo(2); |
| 59 | } |
| 60 | |
| 61 | @Test |
| 62 | void canOverrideSSLSocketFactory() throws IOException, InterruptedException { |
| 63 | server.useHttps(TrustingSSLSocketFactory.get("localhost"), false); |
| 64 | server.enqueue(new MockResponse()); |
| 65 | |
| 66 | TestInterface api = |
| 67 | newBuilder().target(TestInterface.class, "https://localhost:" + server.getPort()); |
| 68 | |
| 69 | api.post("foo"); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * We currently don't include the <a href="http://java.net/jira/browse/JERSEY-639">60-line |
| 74 | * workaround</a> jersey uses to overcome the lack of support for PATCH. For now, prefer okhttp. |
| 75 | * |
| 76 | * @see java.net.HttpURLConnection#setRequestMethod |
| 77 | */ |
| 78 | @Test |
| 79 | @Override |
| 80 | public void patch() throws Exception { |
| 81 | RetryableException exception = assertThrows(RetryableException.class, super::patch); |
| 82 | assertThat(exception).hasCauseInstanceOf(ProtocolException.class); |
| 83 | } |
| 84 | |
| 85 | @Test |
| 86 | @Override |
| 87 | public void noResponseBodyForPost() throws Exception { |
| 88 | super.noResponseBodyForPost(); |
| 89 | MockWebServerAssertions.assertThat(server.takeRequest()) |
| 90 | .hasMethod("POST") |
| 91 | .hasNoHeaderNamed("Content-Type"); |
| 92 | } |
| 93 | |
| 94 | @Test |
| 95 | @EnabledIfSystemProperty(named = "sun.net.http.allowRestrictedHeaders", matches = "true") |