use of io.netty.handler.codec.http.DefaultHttpHeaders in project async-http-client by AsyncHttpClient.
the class BasicHttpTest method cancelledFutureThrowsCancellationException.
@Test(expectedExceptions = CancellationException.class)
public void cancelledFutureThrowsCancellationException() throws Throwable {
withClient().run(client -> {
withServer(server).run(server -> {
HttpHeaders headers = new DefaultHttpHeaders();
headers.add("X-Delay", 5_000);
server.enqueueEcho();
Future<Response> future = client.prepareGet(getTargetUrl()).setHeaders(headers).execute(new AsyncCompletionHandlerAdapter() {
@Override
public void onThrowable(Throwable t) {
}
});
future.cancel(true);
future.get(TIMEOUT, SECONDS);
});
});
}
use of io.netty.handler.codec.http.DefaultHttpHeaders in project async-http-client by AsyncHttpClient.
the class BasicHttpTest method configRequestTimeoutHappensInDueTime.
@Test(expectedExceptions = TimeoutException.class)
public void configRequestTimeoutHappensInDueTime() throws Throwable {
withClient(config().setRequestTimeout(1_000)).run(client -> {
withServer(server).run(server -> {
HttpHeaders h = new DefaultHttpHeaders();
h.add(CONTENT_TYPE, HttpHeaderValues.APPLICATION_X_WWW_FORM_URLENCODED);
h.add("X-Delay", 2_000);
server.enqueueEcho();
long start = unpreciseMillisTime();
try {
client.prepareGet(getTargetUrl()).setHeaders(h).setUrl(getTargetUrl()).execute().get();
} catch (Throwable ex) {
final long elapsedTime = unpreciseMillisTime() - start;
assertTrue(elapsedTime >= 1_000 && elapsedTime <= 1_500);
throw ex.getCause();
}
});
});
}
use of io.netty.handler.codec.http.DefaultHttpHeaders in project async-http-client by AsyncHttpClient.
the class BasicHttpTest method postFormParametersAsBodyString.
@Test
public void postFormParametersAsBodyString() throws Throwable {
withClient().run(client -> {
withServer(server).run(server -> {
HttpHeaders h = new DefaultHttpHeaders();
h.add(CONTENT_TYPE, HttpHeaderValues.APPLICATION_X_WWW_FORM_URLENCODED);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 5; i++) {
sb.append("param_").append(i).append("=value_").append(i).append("&");
}
sb.setLength(sb.length() - 1);
server.enqueueEcho();
client.preparePost(getTargetUrl()).setHeaders(h).setBody(sb.toString()).execute(new AsyncCompletionHandlerAdapter() {
@Override
public Response onCompleted(Response response) throws Exception {
assertEquals(response.getStatusCode(), 200);
for (int i = 1; i < 5; i++) {
assertEquals(response.getHeader("X-param_" + i), "value_" + i);
}
return response;
}
}).get(TIMEOUT, SECONDS);
});
});
}
use of io.netty.handler.codec.http.DefaultHttpHeaders in project async-http-client by AsyncHttpClient.
the class BasicHttpTest method getWithHeaders.
@Test
public void getWithHeaders() throws Throwable {
withClient().run(client -> {
withServer(server).run(server -> {
HttpHeaders h = new DefaultHttpHeaders();
for (int i = 1; i < 5; i++) {
h.add("Test" + i, "Test" + i);
}
server.enqueueEcho();
client.executeRequest(get(getTargetUrl()).setHeaders(h), new AsyncCompletionHandlerAdapter() {
@Override
public Response onCompleted(Response response) throws Exception {
assertEquals(response.getStatusCode(), 200);
for (int i = 1; i < 5; i++) {
assertEquals(response.getHeader("X-Test" + i), "Test" + i);
}
return response;
}
}).get(TIMEOUT, SECONDS);
});
});
}
Aggregations