use of io.netty.handler.codec.http.DefaultHttpHeaders in project async-http-client by AsyncHttpClient.
the class ResumableAsyncHandlerTest method testOnHeadersReceivedContentLengthMinus.
@Test
public void testOnHeadersReceivedContentLengthMinus() throws Exception {
ResumableAsyncHandler handler = new ResumableAsyncHandler();
HttpHeaders responseHeaders = new DefaultHttpHeaders();
responseHeaders.add(CONTENT_LENGTH, -1);
HttpResponseHeaders headers = new HttpResponseHeaders(responseHeaders);
State status = handler.onHeadersReceived(headers);
assertEquals(status, AsyncHandler.State.ABORT, "State should be ABORT for content length -1");
}
use of io.netty.handler.codec.http.DefaultHttpHeaders in project async-http-client by AsyncHttpClient.
the class ResumableAsyncHandlerTest method testOnHeadersReceivedWithDecoratedAsyncHandler.
@Test
public void testOnHeadersReceivedWithDecoratedAsyncHandler() throws Exception {
HttpHeaders responseHeaders = new DefaultHttpHeaders();
HttpResponseHeaders headers = new HttpResponseHeaders(responseHeaders);
@SuppressWarnings("unchecked") AsyncHandler<Response> decoratedAsyncHandler = mock(AsyncHandler.class);
State mockState = mock(State.class);
when(decoratedAsyncHandler.onHeadersReceived(headers)).thenReturn(mockState);
ResumableAsyncHandler handler = new ResumableAsyncHandler(decoratedAsyncHandler);
State status = handler.onHeadersReceived(headers);
assertEquals(status, mockState, "State should be equal to the state returned from decoratedAsyncHandler");
}
use of io.netty.handler.codec.http.DefaultHttpHeaders in project async-http-client by AsyncHttpClient.
the class NettyAsyncResponseTest method testCookieParseWeirdExpiresValue.
@Test(groups = "standalone")
public void testCookieParseWeirdExpiresValue() {
final String cookieDef = "efmembercheck=true; expires=60; path=/; domain=.eclipse.org";
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);
assertEquals(cookie.maxAge(), Long.MIN_VALUE);
}
use of io.netty.handler.codec.http.DefaultHttpHeaders in project async-http-client by AsyncHttpClient.
the class NettyAsyncResponseTest method testCookieParseMaxAge.
@Test(groups = "standalone")
public void testCookieParseMaxAge() {
final String cookieDef = "efmembercheck=true; max-age=60; path=/; domain=.eclipse.org";
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);
assertEquals(cookie.maxAge(), 60);
}
use of io.netty.handler.codec.http.DefaultHttpHeaders in project async-http-client by AsyncHttpClient.
the class BasicHttpTest method postInputStreamWithContentLengthAsBodyGenerator.
@Test
public void postInputStreamWithContentLengthAsBodyGenerator() 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 {
assertNull(request.getHeader(TRANSFER_ENCODING.toString()));
assertEquals(request.getHeader(CONTENT_LENGTH.toString()), Integer.toString("{}".getBytes(StandardCharsets.ISO_8859_1).length));
chain.handle(target, request, httpServletRequest, httpServletResponse);
}
});
byte[] bodyBytes = "{}".getBytes(StandardCharsets.ISO_8859_1);
InputStream bodyStream = new ByteArrayInputStream(bodyBytes);
client.preparePost(getTargetUrl()).setHeaders(h).setBody(new InputStreamBodyGenerator(bodyStream, bodyBytes.length)).execute(new AsyncCompletionHandlerAdapter() {
@Override
public Response onCompleted(Response response) throws Exception {
assertEquals(response.getStatusCode(), 200);
assertEquals(response.getResponseBody(), "{}");
return response;
}
}).get(TIMEOUT, SECONDS);
});
});
}
Aggregations