Search in sources :

Example 21 with DefaultCookie

use of io.netty.handler.codec.http.cookie.DefaultCookie in project async-http-client by AsyncHttpClient.

the class BasicHttpTest method getWithCookies.

@Test
public void getWithCookies() throws Throwable {
    withClient().run(client -> {
        withServer(server).run(server -> {
            final Cookie coo = new DefaultCookie("foo", "value");
            coo.setDomain("/");
            coo.setPath("/");
            server.enqueueEcho();
            client.prepareGet(getTargetUrl()).addCookie(coo).execute(new AsyncCompletionHandlerAdapter() {

                @Override
                public Response onCompleted(Response response) throws Exception {
                    assertEquals(response.getStatusCode(), 200);
                    List<Cookie> cookies = response.getCookies();
                    assertEquals(cookies.size(), 1);
                    assertEquals(cookies.get(0).toString(), "foo=value");
                    return response;
                }
            }).get(TIMEOUT, SECONDS);
        });
    });
}
Also used : Cookie(io.netty.handler.codec.http.cookie.Cookie) DefaultCookie(io.netty.handler.codec.http.cookie.DefaultCookie) HttpServletResponse(javax.servlet.http.HttpServletResponse) DefaultCookie(io.netty.handler.codec.http.cookie.DefaultCookie) AsyncCompletionHandlerAdapter(org.asynchttpclient.test.TestUtils.AsyncCompletionHandlerAdapter) Test(org.testng.annotations.Test) HttpTest(org.asynchttpclient.testserver.HttpTest)

Aggregations

DefaultCookie (io.netty.handler.codec.http.cookie.DefaultCookie)21 Cookie (io.netty.handler.codec.http.cookie.Cookie)15 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)12 DefaultHttpHeaders (io.netty.handler.codec.http.DefaultHttpHeaders)11 Test (org.junit.Test)11 Charset (java.nio.charset.Charset)7 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)5 HttpRequest (io.netty.handler.codec.http.HttpRequest)4 HttpMethod (io.netty.handler.codec.http.HttpMethod)3 HttpVersion (io.netty.handler.codec.http.HttpVersion)3 HashMap (java.util.HashMap)3 List (java.util.List)3 RequestInfo (com.nike.riposte.server.http.RequestInfo)2 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)2 DataProviderRunner (com.tngtech.java.junit.dataprovider.DataProviderRunner)2 ByteBuf (io.netty.buffer.ByteBuf)2 Channel (io.netty.channel.Channel)2 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)2 QueryStringDecoder (io.netty.handler.codec.http.QueryStringDecoder)2 ResponseCookie (org.springframework.http.ResponseCookie)2