Search in sources :

Example 81 with HttpServerExchange

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

the class SimpleParserTestCase method testColonSlashInURL.

@Test
public void testColonSlashInURL() throws BadRequestException {
    byte[] in = "GET /a/http://myurl.com/b/c HTTP/1.1\r\n\r\n".getBytes();
    final 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("/a/http://myurl.com/b/c", result.getRequestPath());
    Assert.assertEquals("/a/http://myurl.com/b/c", result.getRequestURI());
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) UnitTest(io.undertow.testutils.category.UnitTest) Test(org.junit.Test)

Example 82 with HttpServerExchange

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

the class SimpleParserTestCase method runTest.

private void runTest(final byte[] in, String lastHeader) throws BadRequestException {
    parseState.reset();
    HttpServerExchange result = new HttpServerExchange(null);
    HttpRequestParser.instance(OptionMap.EMPTY).handle(ByteBuffer.wrap(in), parseState, result);
    Assert.assertSame(Methods.GET, result.getRequestMethod());
    Assert.assertEquals("/somepath", result.getRequestURI());
    Assert.assertSame(Protocols.HTTP_1_1, result.getProtocol());
    Assert.assertEquals(2, result.getRequestHeaders().getHeaderNames().size());
    Assert.assertEquals("www.somehost.net", result.getRequestHeaders().getFirst(new HttpString("Host")));
    Assert.assertEquals(lastHeader, result.getRequestHeaders().getFirst(new HttpString("OtherHeader")));
    Assert.assertEquals(ParseState.PARSE_COMPLETE, parseState.state);
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) HttpString(io.undertow.util.HttpString)

Example 83 with HttpServerExchange

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

the class SimpleParserTestCase method testMatrixParamFlagEndingWithNormalPath.

@Test
public void testMatrixParamFlagEndingWithNormalPath() throws BadRequestException {
    byte[] in = "GET /somepath;p1/more 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("/somepath;p1/more", result.getRequestURI());
    Assert.assertEquals("/somepath/more", result.getRequestPath());
    Assert.assertEquals(1, result.getPathParameters().size());
    Assert.assertEquals("p1", result.getPathParameters().keySet().toArray()[0]);
    Assert.assertSame(Protocols.HTTP_1_1, result.getProtocol());
    Assert.assertFalse(result.isHostIncludedInRequestURI());
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) UnitTest(io.undertow.testutils.category.UnitTest) Test(org.junit.Test)

Example 84 with HttpServerExchange

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

the class SimpleParserTestCase method testServletURLWithPathParamEndingWithNormalPath.

@Test
public void testServletURLWithPathParamEndingWithNormalPath() throws BadRequestException {
    byte[] in = "GET http://localhost:7777/servletContext/aaaa/b;param=1/cccc 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("http://localhost:7777/servletContext/aaaa/b;param=1/cccc", result.getRequestURI());
    Assert.assertEquals("/servletContext/aaaa/b/cccc", result.getRequestPath());
    Assert.assertEquals(1, result.getPathParameters().size());
    Assert.assertEquals("param", result.getPathParameters().keySet().toArray()[0]);
    Assert.assertEquals("1", result.getPathParameters().get("param").getFirst());
    Assert.assertSame(Protocols.HTTP_1_1, result.getProtocol());
    Assert.assertTrue(result.isHostIncludedInRequestURI());
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) UnitTest(io.undertow.testutils.category.UnitTest) Test(org.junit.Test)

Example 85 with HttpServerExchange

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

the class SimpleParserTestCase method testNonEncodedAsciiCharacters.

@Test(expected = BadRequestException.class)
public void testNonEncodedAsciiCharacters() throws UnsupportedEncodingException, BadRequestException {
    byte[] in = "GET /bår HTTP/1.1\r\n\r\n".getBytes("ISO-8859-1");
    final ParseState context = new ParseState(10);
    HttpServerExchange result = new HttpServerExchange(null);
    HttpRequestParser.instance(OptionMap.EMPTY).handle(ByteBuffer.wrap(in), context, result);
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) UnitTest(io.undertow.testutils.category.UnitTest) Test(org.junit.Test)

Aggregations

HttpServerExchange (io.undertow.server.HttpServerExchange)277 HttpHandler (io.undertow.server.HttpHandler)127 Test (org.junit.Test)109 IOException (java.io.IOException)90 UnitTest (io.undertow.testutils.category.UnitTest)45 BeforeClass (org.junit.BeforeClass)44 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 SessionConfig (io.undertow.server.session.SessionConfig)16 Map (java.util.Map)16 Sender (io.undertow.io.Sender)15 ExchangeCompletionListener (io.undertow.server.ExchangeCompletionListener)14 HeaderMap (io.undertow.util.HeaderMap)13 URI (java.net.URI)13 HeaderValues (io.undertow.util.HeaderValues)12