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