Search in sources :

Example 86 with HttpServerExchange

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

the class SimpleParserTestCase method testServletPathWithPathParam.

@Test
public void testServletPathWithPathParam() throws BadRequestException {
    byte[] in = "GET /servletContext/aaaa/b;param=1 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/aaaa/b;param=1", result.getRequestURI());
    Assert.assertEquals("/servletContext/aaaa/b", 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.assertFalse(result.isHostIncludedInRequestURI());
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) UnitTest(io.undertow.testutils.category.UnitTest) Test(org.junit.Test)

Example 87 with HttpServerExchange

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

the class SimpleParserTestCase method testNonEncodedAsciiCharactersExplicitlyAllowed.

@Test
public void testNonEncodedAsciiCharactersExplicitlyAllowed() 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.create(UndertowOptions.ALLOW_UNESCAPED_CHARACTERS_IN_URL, true)).handle(ByteBuffer.wrap(in), context, result);
    Assert.assertSame(Methods.GET, result.getRequestMethod());
    Assert.assertEquals("/bår", result.getRequestPath());
    // not decoded
    Assert.assertEquals("/bår", result.getRequestURI());
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) UnitTest(io.undertow.testutils.category.UnitTest) Test(org.junit.Test)

Example 88 with HttpServerExchange

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

the class SimpleParserTestCase method testEmptyQueryParams.

@Test
public void testEmptyQueryParams() throws BadRequestException {
    byte[] in = "GET /clusterbench/requestinfo//?;?=44&test=OK;devil=3&&&&&&&&&&&&&&&&&&&&&&&&&&&&777=666 HTTP/1.1\r\n\r\n".getBytes();
    final ParseState context = new ParseState(10);
    HttpServerExchange result = new HttpServerExchange(null);
    HttpRequestParser.instance(OptionMap.EMPTY).handle(ByteBuffer.wrap(in), context, result);
    Assert.assertSame(Methods.GET, result.getRequestMethod());
    Assert.assertEquals("/clusterbench/requestinfo//", result.getRequestURI());
    Assert.assertEquals("/clusterbench/requestinfo//", result.getRequestPath());
    Assert.assertEquals(3, result.getQueryParameters().size());
    Assert.assertEquals("OK;devil=3", result.getQueryParameters().get("test").getFirst());
    Assert.assertEquals("666", result.getQueryParameters().get("777").getFirst());
    Assert.assertEquals("44", result.getQueryParameters().get(";?").getFirst());
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) UnitTest(io.undertow.testutils.category.UnitTest) Test(org.junit.Test)

Example 89 with HttpServerExchange

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

the class SimpleParserTestCase method testPlusSignVsSpaceEncodingInPath.

/**
 * Test for having mixed + and %20 in path for encoding spaces https://issues.jboss.org/browse/UNDERTOW-1193
 */
@Test
public void testPlusSignVsSpaceEncodingInPath() throws BadRequestException {
    byte[] in = "GET http://myurl.com/+/mypath%20with%20spaces 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("+ in path shouldn't be treated as space, caused probably by https://issues.jboss.org/browse/UNDERTOW-1193", "/+/mypath with spaces", result.getRequestPath());
    Assert.assertEquals("http://myurl.com/+/mypath%20with%20spaces", result.getRequestURI());
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) UnitTest(io.undertow.testutils.category.UnitTest) Test(org.junit.Test)

Example 90 with HttpServerExchange

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

the class SimpleParserTestCase method testServletURLMultiLevelMatrixParameterEndingWithNormalPathAndQuery.

@Test
public void testServletURLMultiLevelMatrixParameterEndingWithNormalPathAndQuery() throws BadRequestException {
    byte[] in = "GET http://localhost:7777/some;p1=v1/path;p1=v2/more?q1=v3 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/some;p1=v1/path;p1=v2/more", result.getRequestURI());
    Assert.assertEquals("/some/path/more", result.getRequestPath());
    Assert.assertEquals("q1=v3", result.getQueryString());
    Assert.assertEquals("v1", result.getPathParameters().get("p1").getFirst());
    Assert.assertEquals("v2", result.getPathParameters().get("p1").getLast());
    Assert.assertEquals("v3", result.getQueryParameters().get("q1").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)

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