use of io.vertx.ext.web.client.impl.ClientPhase in project vertx-web by vert-x3.
the class InterceptorTest method testFollowRedirects.
@Test
public void testFollowRedirects() throws Exception {
server.requestHandler(req -> {
switch(req.path()) {
case "/1":
req.response().setStatusCode(302).putHeader("location", "http://localhost:8080/2").end();
break;
default:
req.response().end();
}
});
startServer();
List<ClientPhase> phases = new ArrayList<>();
List<String> requestUris = new ArrayList<>();
AtomicInteger redirects = new AtomicInteger();
client.addInterceptor(ctx -> {
phases.add(ctx.phase());
switch(ctx.phase()) {
case PREPARE_REQUEST:
assertEquals(0, ctx.redirects());
break;
case SEND_REQUEST:
assertEquals(redirects.getAndIncrement(), ctx.redirects());
requestUris.add(ctx.requestOptions().getURI());
break;
}
ctx.next();
});
HttpRequest<Buffer> builder = client.get("/1").host("localhost").port(8080);
builder.send(onSuccess(resp -> {
assertEquals(200, resp.statusCode());
assertEquals(Arrays.asList(ClientPhase.PREPARE_REQUEST, ClientPhase.CREATE_REQUEST, ClientPhase.SEND_REQUEST, ClientPhase.FOLLOW_REDIRECT, ClientPhase.CREATE_REQUEST, ClientPhase.SEND_REQUEST, ClientPhase.RECEIVE_RESPONSE, ClientPhase.DISPATCH_RESPONSE), phases);
assertEquals(Arrays.asList("/1", "/2"), requestUris);
complete();
}));
await();
}
Aggregations