use of io.netty.handler.codec.http.DefaultHttpHeaders in project riposte by Nike-Inc.
the class RequestInfoForLoggingRiposteAdapterTest method getHeaderMapDelegatesToRequestInfoAndCachesResult.
@Test
public void getHeaderMapDelegatesToRequestInfoAndCachesResult() {
Map<String, List<String>> expectedHeaderMap = new TreeMap<>(MapBuilder.<String, List<String>>builder().put("header1", Arrays.asList("h1val1")).put("header2", Arrays.asList("h2val1", "h2val2")).build());
HttpHeaders nettyHeaders = new DefaultHttpHeaders();
for (Map.Entry<String, List<String>> headerEntry : expectedHeaderMap.entrySet()) {
nettyHeaders.add(headerEntry.getKey(), headerEntry.getValue());
}
setFieldOnRequestInfo("headers", nettyHeaders);
Map<String, List<String>> actualHeaderMap = adapter.getHeadersMap();
assertThat(actualHeaderMap, is(expectedHeaderMap));
assertThat(adapter.getHeadersMap(), sameInstance(actualHeaderMap));
}
use of io.netty.handler.codec.http.DefaultHttpHeaders in project async-http-client by AsyncHttpClient.
the class BasicHttpTest method postUnboundedInputStreamAsBodyStream.
@Test
public void postUnboundedInputStreamAsBodyStream() throws Throwable {
withClient().run(client -> {
withServer(server).run(server -> {
HttpHeaders h = new DefaultHttpHeaders();
h.add(CONTENT_TYPE, HttpHeaderValues.APPLICATION_JSON);
server.enqueue(new AbstractHandler() {
EchoHandler chain = new EchoHandler();
@Override
public void handle(String target, org.eclipse.jetty.server.Request request, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException, ServletException {
assertEquals(request.getHeader(TRANSFER_ENCODING.toString()), HttpHeaderValues.CHUNKED.toString());
assertNull(request.getHeader(CONTENT_LENGTH.toString()));
chain.handle(target, request, httpServletRequest, httpServletResponse);
}
});
server.enqueueEcho();
client.preparePost(getTargetUrl()).setHeaders(h).setBody(new ByteArrayInputStream("{}".getBytes(StandardCharsets.ISO_8859_1))).execute(new AsyncCompletionHandlerAdapter() {
@Override
public Response onCompleted(Response response) throws Exception {
assertEquals(response.getStatusCode(), 200);
assertEquals(response.getResponseBody(), "{}");
return response;
}
}).get(TIMEOUT, SECONDS);
});
});
}
use of io.netty.handler.codec.http.DefaultHttpHeaders in project async-http-client by AsyncHttpClient.
the class BasicHttpTest method postFormParametersAsBodyStream.
@Test
public void postFormParametersAsBodyStream() 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(new ByteArrayInputStream(sb.toString().getBytes(StandardCharsets.UTF_8))).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 NettyAsyncResponseTest method testCookieParseExpires.
@Test(groups = "standalone")
public void testCookieParseExpires() {
// e.g. "Tue, 27 Oct 2015 12:54:24 GMT";
SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
Date date = new Date(System.currentTimeMillis() + 60000);
final String cookieDef = String.format("efmembercheck=true; expires=%s; path=/; domain=.eclipse.org", sdf.format(date));
HttpResponseHeaders responseHeaders = new HttpResponseHeaders(new DefaultHttpHeaders().add(SET_COOKIE, cookieDef));
NettyResponse response = new NettyResponse(new NettyResponseStatus(null, null, null), responseHeaders, null);
List<Cookie> cookies = response.getCookies();
assertEquals(cookies.size(), 1);
Cookie cookie = cookies.get(0);
assertTrue(cookie.maxAge() >= 58 && cookie.maxAge() <= 60);
}
use of io.netty.handler.codec.http.DefaultHttpHeaders in project async-http-client by AsyncHttpClient.
the class ResumableAsyncHandlerTest method testOnHeadersReceived.
@Test
public void testOnHeadersReceived() throws Exception {
ResumableAsyncHandler handler = new ResumableAsyncHandler();
HttpHeaders responseHeaders = new DefaultHttpHeaders();
HttpResponseHeaders headers = new HttpResponseHeaders(responseHeaders);
State status = handler.onHeadersReceived(headers);
assertEquals(status, AsyncHandler.State.CONTINUE, "State should be CONTINUE for a successful onHeadersReceived");
}
Aggregations