try { response = sendImpl(); int s = response.status(); if (s == 429 || s == 503) {
try { response = sendImpl(); int s = response.status(); if (s == 429 || s == 503) {
private void retryStatus(HttpResponse expectedRes, int expectedAttempts) throws IOException { AtomicInteger attempts = new AtomicInteger(); HttpResponseSupplier supplier = () -> { attempts.incrementAndGet(); return expectedRes; }; HttpResponse res = new TestRequestBuilder(supplier) .withInitialRetryDelay(0L) .withRetries(2) .send(); Assertions.assertEquals(expectedAttempts, attempts.get()); Assertions.assertEquals(expectedRes.status(), res.status()); }
@Test public void hostnameVerificationWithHTTPS() throws IOException { HttpResponse res = new TestRequestBuilder(() -> OK, URI.create("https://foo.com/path")) .allowAllHosts() .send(); Assertions.assertEquals(200, res.status()); }
@Test public void ok() throws IOException { HttpResponse res = new TestRequestBuilder(() -> OK).send(); Assertions.assertEquals(200, res.status()); }
@Test public void ok() throws IOException { HttpResponse res = HttpClient.DEFAULT .get(uri("/ok")) .addHeader("X-Status", "200") .addHeader("X-Length", "-1") .send(); Assertions.assertEquals(200, res.status()); }
@Test public void unavailableEmptyChunked() throws IOException { HttpResponse res = HttpClient.DEFAULT .get(uri("/ok")) .addHeader("X-Status", "503") .addHeader("X-Length", "0") .send(); Assertions.assertEquals(503, res.status()); }
@Test public void emptyChunked() throws IOException { HttpResponse res = HttpClient.DEFAULT .get(uri("/ok")) .addHeader("X-Status", "200") .addHeader("X-Length", "0") .send(); Assertions.assertEquals(200, res.status()); }
@Test public void unavailableEmpty() throws IOException { HttpResponse res = HttpClient.DEFAULT .get(uri("/ok")) .addHeader("X-Status", "503") .addHeader("X-Length", "-1") .send(); Assertions.assertEquals(503, res.status()); }
@Test public void okWithBody() throws IOException { HttpResponse res = HttpClient.DEFAULT .post(uri("/echo")) .addHeader("X-Status", "200") .withContent("text/plain", "foo") .send(); Assertions.assertEquals(200, res.status()); Assertions.assertEquals("foo", res.entityAsString()); }
@Test public void okWithCompressedBody() throws IOException { HttpResponse res = HttpClient.DEFAULT .post(uri("/echo")) .acceptGzip() .addHeader("X-Status", "200") .withContent("text/plain", "foo") .compress() .send() .decompress(); Assertions.assertEquals(200, res.status()); Assertions.assertEquals("foo", res.entityAsString()); } }