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