Search in sources :

Example 26 with HttpServerExchange

use of io.undertow.server.HttpServerExchange in project undertow by undertow-io.

the class ResumeWritesTestCase method testResumeWritesFixedLength.

@Test
public void testResumeWritesFixedLength() throws IOException {
    DefaultServer.setRootHandler(new HttpHandler() {

        @Override
        public void handleRequest(final HttpServerExchange exchange) throws Exception {
            exchange.addResponseWrapper(new ReturnZeroWrapper());
            exchange.getResponseHeaders().put(Headers.CONTENT_LENGTH, HELLO_WORLD.length());
            exchange.getResponseSender().send(HELLO_WORLD);
        }
    });
    TestHttpClient client = new TestHttpClient();
    try {
        HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/path");
        HttpResponse result = client.execute(get);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        Assert.assertEquals(HELLO_WORLD, HttpClientUtils.readResponse(result));
        result = client.execute(get);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        Assert.assertEquals(HELLO_WORLD, HttpClientUtils.readResponse(result));
        result = client.execute(get);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        Assert.assertEquals(HELLO_WORLD, HttpClientUtils.readResponse(result));
    } finally {
        client.getConnectionManager().shutdown();
    }
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) HttpHandler(io.undertow.server.HttpHandler) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) TestHttpClient(io.undertow.testutils.TestHttpClient) Test(org.junit.Test)

Example 27 with HttpServerExchange

use of io.undertow.server.HttpServerExchange in project undertow by undertow-io.

the class ResumeWritesTestCase method testResumeWritesChunked.

@Test
public void testResumeWritesChunked() throws IOException {
    DefaultServer.setRootHandler(new HttpHandler() {

        @Override
        public void handleRequest(final HttpServerExchange exchange) throws Exception {
            exchange.addResponseWrapper(new ReturnZeroWrapper());
            exchange.getResponseSender().send(HELLO_WORLD);
        }
    });
    TestHttpClient client = new TestHttpClient();
    try {
        HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/path");
        HttpResponse result = client.execute(get);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        Assert.assertEquals(HELLO_WORLD, HttpClientUtils.readResponse(result));
        result = client.execute(get);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        Assert.assertEquals(HELLO_WORLD, HttpClientUtils.readResponse(result));
        result = client.execute(get);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        Assert.assertEquals(HELLO_WORLD, HttpClientUtils.readResponse(result));
    } finally {
        client.getConnectionManager().shutdown();
    }
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) HttpHandler(io.undertow.server.HttpHandler) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) TestHttpClient(io.undertow.testutils.TestHttpClient) Test(org.junit.Test)

Example 28 with HttpServerExchange

use of io.undertow.server.HttpServerExchange in project undertow by undertow-io.

the class SameSiteCookieHandlerTestCase method testNoneWithoutSecure.

@Test
public void testNoneWithoutSecure() throws IOException {
    DefaultServer.setRootHandler(new SameSiteCookieHandler(new HttpHandler() {

        @Override
        public void handleRequest(final HttpServerExchange exchange) throws Exception {
            exchange.setResponseCookie(new CookieImpl("foo", "bar"));
        }
    }, "None", "foo", true, true, false));
    DefaultServer.startSSLServer();
    TestHttpClient client = new TestHttpClient();
    client.setSSLContext(DefaultServer.getClientSSLContext());
    try {
        HttpGet get = new HttpGet(DefaultServer.getDefaultServerSSLAddress());
        HttpResponse result = client.execute(get);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        Header header = result.getFirstHeader("set-cookie");
        Assert.assertEquals("foo=bar; SameSite=None", header.getValue());
        FileUtils.readFile(result.getEntity().getContent());
    } finally {
        client.getConnectionManager().shutdown();
        DefaultServer.stopSSLServer();
    }
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) HttpHandler(io.undertow.server.HttpHandler) Header(org.apache.http.Header) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) TestHttpClient(io.undertow.testutils.TestHttpClient) Test(org.junit.Test)

Example 29 with HttpServerExchange

use of io.undertow.server.HttpServerExchange in project undertow by undertow-io.

the class SameSiteCookieHandlerTestCase method testStrict.

@Test
public void testStrict() throws IOException {
    DefaultServer.setRootHandler(new SameSiteCookieHandler(new HttpHandler() {

        @Override
        public void handleRequest(final HttpServerExchange exchange) throws Exception {
            exchange.setResponseCookie(new CookieImpl("foo", "bar"));
        }
    }, "Strict", "foo"));
    DefaultServer.startSSLServer();
    TestHttpClient client = new TestHttpClient();
    client.setSSLContext(DefaultServer.getClientSSLContext());
    try {
        HttpGet get = new HttpGet(DefaultServer.getDefaultServerSSLAddress());
        HttpResponse result = client.execute(get);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        Header header = result.getFirstHeader("set-cookie");
        Assert.assertEquals("foo=bar; SameSite=Strict", header.getValue());
        FileUtils.readFile(result.getEntity().getContent());
    } finally {
        client.getConnectionManager().shutdown();
        DefaultServer.stopSSLServer();
    }
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) HttpHandler(io.undertow.server.HttpHandler) Header(org.apache.http.Header) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) TestHttpClient(io.undertow.testutils.TestHttpClient) Test(org.junit.Test)

Example 30 with HttpServerExchange

use of io.undertow.server.HttpServerExchange in project undertow by undertow-io.

the class SameSiteCookieHandlerTestCase method testPatternUnmatched.

@Test
public void testPatternUnmatched() throws IOException {
    DefaultServer.setRootHandler(new SameSiteCookieHandler(new HttpHandler() {

        @Override
        public void handleRequest(final HttpServerExchange exchange) throws Exception {
            exchange.setResponseCookie(new CookieImpl("foo", "bar"));
        }
    }, "Lax", "FO.*"));
    DefaultServer.startSSLServer();
    TestHttpClient client = new TestHttpClient();
    client.setSSLContext(DefaultServer.getClientSSLContext());
    try {
        HttpGet get = new HttpGet(DefaultServer.getDefaultServerSSLAddress());
        HttpResponse result = client.execute(get);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        Header header = result.getFirstHeader("set-cookie");
        Assert.assertEquals("foo=bar", header.getValue());
        FileUtils.readFile(result.getEntity().getContent());
    } finally {
        client.getConnectionManager().shutdown();
        DefaultServer.stopSSLServer();
    }
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) HttpHandler(io.undertow.server.HttpHandler) Header(org.apache.http.Header) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) TestHttpClient(io.undertow.testutils.TestHttpClient) Test(org.junit.Test)

Aggregations

HttpServerExchange (io.undertow.server.HttpServerExchange)270 HttpHandler (io.undertow.server.HttpHandler)126 Test (org.junit.Test)109 IOException (java.io.IOException)87 UnitTest (io.undertow.testutils.category.UnitTest)45 BeforeClass (org.junit.BeforeClass)43 TestHttpClient (io.undertow.testutils.TestHttpClient)42 HttpGet (org.apache.http.client.methods.HttpGet)40 HttpResponse (org.apache.http.HttpResponse)37 HttpString (io.undertow.util.HttpString)36 Header (org.apache.http.Header)24 Undertow (io.undertow.Undertow)19 ByteBuffer (java.nio.ByteBuffer)19 Map (java.util.Map)16 SessionConfig (io.undertow.server.session.SessionConfig)15 Sender (io.undertow.io.Sender)14 ExchangeCompletionListener (io.undertow.server.ExchangeCompletionListener)14 HeaderMap (io.undertow.util.HeaderMap)13 HeaderValues (io.undertow.util.HeaderValues)12 URI (java.net.URI)12