Search in sources :

Example 36 with DefaultHttpHeaders

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");
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) HttpResponseHeaders(org.asynchttpclient.HttpResponseHeaders) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) State(org.asynchttpclient.AsyncHandler.State) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 37 with DefaultHttpHeaders

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");
}
Also used : Response(org.asynchttpclient.Response) HttpHeaders(io.netty.handler.codec.http.HttpHeaders) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) HttpResponseHeaders(org.asynchttpclient.HttpResponseHeaders) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) State(org.asynchttpclient.AsyncHandler.State) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 38 with DefaultHttpHeaders

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);
}
Also used : Cookie(io.netty.handler.codec.http.cookie.Cookie) HttpResponseHeaders(org.asynchttpclient.HttpResponseHeaders) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) Test(org.testng.annotations.Test)

Example 39 with DefaultHttpHeaders

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);
}
Also used : Cookie(io.netty.handler.codec.http.cookie.Cookie) HttpResponseHeaders(org.asynchttpclient.HttpResponseHeaders) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) Test(org.testng.annotations.Test)

Example 40 with DefaultHttpHeaders

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);
        });
    });
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) InputStreamBodyGenerator(org.asynchttpclient.request.body.generator.InputStreamBodyGenerator) AsyncCompletionHandlerAdapter(org.asynchttpclient.test.TestUtils.AsyncCompletionHandlerAdapter) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) HttpServletResponse(javax.servlet.http.HttpServletResponse) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) ByteArrayInputStream(java.io.ByteArrayInputStream) EchoHandler(org.asynchttpclient.testserver.HttpServer.EchoHandler) Test(org.testng.annotations.Test) HttpTest(org.asynchttpclient.testserver.HttpTest)

Aggregations

DefaultHttpHeaders (io.netty.handler.codec.http.DefaultHttpHeaders)49 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)36 Test (org.testng.annotations.Test)20 Test (org.junit.Test)18 Cookie (io.netty.handler.codec.http.cookie.Cookie)14 DefaultCookie (io.netty.handler.codec.http.cookie.DefaultCookie)12 HttpServletResponse (javax.servlet.http.HttpServletResponse)12 HttpTest (org.asynchttpclient.testserver.HttpTest)12 AsyncCompletionHandlerAdapter (org.asynchttpclient.test.TestUtils.AsyncCompletionHandlerAdapter)11 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)9 Charset (java.nio.charset.Charset)8 HttpResponseHeaders (org.asynchttpclient.HttpResponseHeaders)6 HttpRequest (io.netty.handler.codec.http.HttpRequest)5 RequestInfo (com.nike.riposte.server.http.RequestInfo)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Map (java.util.Map)4 ByteBuf (io.netty.buffer.ByteBuf)3 Channel (io.netty.channel.Channel)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3