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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
Aggregations