use of io.undertow.server.HttpServerExchange in project undertow by undertow-io.
the class SimpleSSLTestCase method testNonPersistentConnections.
@Test
public void testNonPersistentConnections() throws IOException, GeneralSecurityException {
DefaultServer.setRootHandler(new HttpHandler() {
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
exchange.getResponseHeaders().put(HttpString.tryFromString("scheme"), exchange.getRequestScheme());
exchange.getResponseHeaders().put(Headers.CONNECTION, "close");
exchange.endExchange();
}
});
DefaultServer.startSSLServer();
TestHttpClient client = new TestHttpClient();
client.setSSLContext(DefaultServer.getClientSSLContext());
try {
for (int i = 0; i < 5; ++i) {
HttpGet get = new HttpGet(DefaultServer.getDefaultServerSSLAddress());
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
Header[] header = result.getHeaders("scheme");
Assert.assertEquals("https", header[0].getValue());
HttpClientUtils.readResponse(result);
}
} finally {
client.getConnectionManager().shutdown();
DefaultServer.stopSSLServer();
}
}
use of io.undertow.server.HttpServerExchange in project undertow by undertow-io.
the class SimpleSSLTestCase method simpleSSLTestCase.
@Test
public void simpleSSLTestCase() throws IOException, GeneralSecurityException {
DefaultServer.setRootHandler(new HttpHandler() {
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
exchange.getResponseHeaders().put(HttpString.tryFromString("scheme"), exchange.getRequestScheme());
exchange.endExchange();
}
});
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.getHeaders("scheme");
Assert.assertEquals("https", header[0].getValue());
} finally {
client.getConnectionManager().shutdown();
DefaultServer.stopSSLServer();
}
}
use of io.undertow.server.HttpServerExchange in project undertow by undertow-io.
the class FormAuthTestCase method setRootHandler.
@Override
protected void setRootHandler(HttpHandler current) {
final PredicateHandler handler = new PredicateHandler(Predicates.path("/login"), new HttpHandler() {
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
exchange.getResponseSender().send("Login Page");
}
}, current);
super.setRootHandler(new SessionAttachmentHandler(handler, new InMemorySessionManager("test"), new SessionCookieConfig()));
}
use of io.undertow.server.HttpServerExchange in project undertow by undertow-io.
the class SimpleParserTestCase method testServletPathWithPathParams.
@Test
public void testServletPathWithPathParams() throws BadRequestException {
byte[] in = "GET /servletContext/aa/b;foo=bar;mysessioncookie=mSwrYUX8_e3ukAylNMkg3oMRglB4-YjxqeWqXQsI HTTP/1.1\r\n\r\n".getBytes();
ParseState context = new ParseState(10);
HttpServerExchange result = new HttpServerExchange(null);
HttpRequestParser.instance(OptionMap.create(UndertowOptions.ALLOW_ENCODED_SLASH, true)).handle(ByteBuffer.wrap(in), context, result);
Assert.assertSame(Methods.GET, result.getRequestMethod());
Assert.assertEquals("/servletContext/aa/b;foo=bar;mysessioncookie=mSwrYUX8_e3ukAylNMkg3oMRglB4-YjxqeWqXQsI", result.getRequestURI());
Assert.assertEquals("/servletContext/aa/b", result.getRequestPath());
Assert.assertEquals(2, result.getPathParameters().size());
Assert.assertEquals("bar", result.getPathParameters().get("foo").getFirst());
Assert.assertEquals("mSwrYUX8_e3ukAylNMkg3oMRglB4-YjxqeWqXQsI", result.getPathParameters().get("mysessioncookie").getFirst());
Assert.assertSame(Protocols.HTTP_1_1, result.getProtocol());
Assert.assertFalse(result.isHostIncludedInRequestURI());
}
use of io.undertow.server.HttpServerExchange in project undertow by undertow-io.
the class SimpleParserTestCase method testCanonicalPath.
@Test
public void testCanonicalPath() throws BadRequestException {
byte[] in = "GET http://www.somehost.net/somepath HTTP/1.1\nHost: \t www.somehost.net\nOtherHeader:\tsome\n \t value\n\r\n".getBytes();
final ParseState context = new ParseState(5);
HttpServerExchange result = new HttpServerExchange(null);
HttpRequestParser.instance(OptionMap.EMPTY).handle(ByteBuffer.wrap(in), context, result);
Assert.assertEquals("/somepath", result.getRelativePath());
Assert.assertEquals("http://www.somehost.net/somepath", result.getRequestURI());
}
Aggregations