use of org.eclipse.jetty.client.api.Response in project jetty.project by eclipse.
the class HttpClientChunkedContentTest method test_Server_HeadersPauseTerminal_Client_Response.
@Test
public void test_Server_HeadersPauseTerminal_Client_Response() throws Exception {
startClient();
try (ServerSocket server = new ServerSocket()) {
server.bind(new InetSocketAddress("localhost", 0));
final AtomicReference<Result> resultRef = new AtomicReference<>();
final CountDownLatch completeLatch = new CountDownLatch(1);
client.newRequest("localhost", server.getLocalPort()).timeout(5, TimeUnit.SECONDS).send(new Response.CompleteListener() {
@Override
public void onComplete(Result result) {
resultRef.set(result);
completeLatch.countDown();
}
});
try (Socket socket = server.accept()) {
consumeRequestHeaders(socket);
OutputStream output = socket.getOutputStream();
String headers = "" + "HTTP/1.1 200 OK\r\n" + "Transfer-Encoding: chunked\r\n" + "\r\n";
output.write(headers.getBytes(StandardCharsets.UTF_8));
output.flush();
Thread.sleep(1000);
String terminal = "" + "0\r\n" + "\r\n";
output.write(terminal.getBytes(StandardCharsets.UTF_8));
output.flush();
assertTrue(completeLatch.await(5, TimeUnit.SECONDS));
Result result = resultRef.get();
assertTrue(result.isSucceeded());
Response response = result.getResponse();
Assert.assertEquals(200, response.getStatus());
}
}
}
use of org.eclipse.jetty.client.api.Response in project jetty.project by eclipse.
the class HttpClientRedirectTest method test_303.
@Test
public void test_303() throws Exception {
start(new RedirectHandler());
Response response = client.newRequest("localhost", connector.getLocalPort()).scheme(scheme).path("/303/localhost/done").timeout(5, TimeUnit.SECONDS).send();
Assert.assertNotNull(response);
Assert.assertEquals(200, response.getStatus());
Assert.assertFalse(response.getHeaders().containsKey(HttpHeader.LOCATION.asString()));
}
use of org.eclipse.jetty.client.api.Response in project jetty.project by eclipse.
the class HttpClientRedirectTest method testHttpRedirector.
@Test
public void testHttpRedirector() throws Exception {
start(new RedirectHandler());
final HttpRedirector redirector = new HttpRedirector(client);
org.eclipse.jetty.client.api.Request request1 = client.newRequest("localhost", connector.getLocalPort()).scheme(scheme).path("/303/localhost/302/localhost/done").timeout(5, TimeUnit.SECONDS).followRedirects(false);
ContentResponse response1 = request1.send();
Assert.assertEquals(303, response1.getStatus());
Assert.assertTrue(redirector.isRedirect(response1));
Result result = redirector.redirect(request1, response1);
org.eclipse.jetty.client.api.Request request2 = result.getRequest();
Response response2 = result.getResponse();
Assert.assertEquals(302, response2.getStatus());
Assert.assertTrue(redirector.isRedirect(response2));
final CountDownLatch latch = new CountDownLatch(1);
redirector.redirect(request2, response2, r -> {
Response response3 = r.getResponse();
Assert.assertEquals(200, response3.getStatus());
Assert.assertFalse(redirector.isRedirect(response3));
latch.countDown();
});
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
}
use of org.eclipse.jetty.client.api.Response in project jetty.project by eclipse.
the class HttpClientRedirectTest method test_303_WithConnectionClose_WithBigRequest.
@Test
public void test_303_WithConnectionClose_WithBigRequest() throws Exception {
start(new RedirectHandler());
Response response = client.newRequest("localhost", connector.getLocalPort()).scheme(scheme).path("/303/localhost/done?close=true").timeout(5, TimeUnit.SECONDS).send();
Assert.assertNotNull(response);
Assert.assertEquals(200, response.getStatus());
Assert.assertFalse(response.getHeaders().containsKey(HttpHeader.LOCATION.asString()));
}
use of org.eclipse.jetty.client.api.Response in project jetty.project by eclipse.
the class HttpClientRedirectTest method testAbsoluteURIPathWithSpaces.
@Test
public void testAbsoluteURIPathWithSpaces() throws Exception {
start(new RedirectHandler());
Response response = client.newRequest("localhost", connector.getLocalPort()).scheme(scheme).path("/303/localhost/a+space?decode=true").timeout(5, TimeUnit.SECONDS).send();
Assert.assertNotNull(response);
Assert.assertEquals(200, response.getStatus());
Assert.assertFalse(response.getHeaders().containsKey(HttpHeader.LOCATION.asString()));
}
Aggregations