use of io.undertow.server.HttpServerExchange in project undertow by undertow-io.
the class SimpleParserTestCase method testMultipleMatrixParamsOfSameName.
@Test
public void testMultipleMatrixParamsOfSameName() throws BadRequestException {
byte[] in = "GET /somepath;p1=v1;p1=v2 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=v1;p1=v2", result.getRequestURI());
Assert.assertEquals("/somepath", result.getRequestPath());
Assert.assertEquals(1, result.getPathParameters().size());
Assert.assertEquals("p1", result.getPathParameters().keySet().toArray()[0]);
Assert.assertEquals("v1", result.getPathParameters().get("p1").getFirst());
Assert.assertEquals("v2", result.getPathParameters().get("p1").getLast());
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 testQueryParams.
@Test
public void testQueryParams() throws BadRequestException {
byte[] in = "GET http://www.somehost.net/somepath?a=b&b=c&d&e&f= HTTP/1.1\nHost: \t www.somehost.net\nOtherHeader:\tsome\n \t value\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.assertEquals("/somepath", result.getRelativePath());
Assert.assertEquals("http://www.somehost.net/somepath", result.getRequestURI());
Assert.assertEquals("a=b&b=c&d&e&f=", result.getQueryString());
Assert.assertEquals("b", result.getQueryParameters().get("a").getFirst());
Assert.assertEquals("c", result.getQueryParameters().get("b").getFirst());
Assert.assertEquals("", result.getQueryParameters().get("d").getFirst());
Assert.assertEquals("", result.getQueryParameters().get("e").getFirst());
Assert.assertEquals("", result.getQueryParameters().get("f").getFirst());
}
use of io.undertow.server.HttpServerExchange in project undertow by undertow-io.
the class SimpleParserTestCase method testDifferentCaseHeaders.
@Test
public void testDifferentCaseHeaders() throws BadRequestException {
final ParseState context = new ParseState(10);
HttpServerExchange result = new HttpServerExchange(null);
byte[] in = "GET /somepath HTTP/1.1\r\nHost: www.somehost.net\r\nhost: other\r\n\r\n".getBytes();
HttpRequestParser.instance(OptionMap.EMPTY).handle(ByteBuffer.wrap(in), context, result);
Assert.assertArrayEquals(result.getRequestHeaders().get("HOST").toArray(), new String[] { "www.somehost.net", "other" });
}
use of io.undertow.server.HttpServerExchange in project undertow by undertow-io.
the class SimpleParserTestCase method testEncodedSlashDisallowed.
@Test
public void testEncodedSlashDisallowed() throws BadRequestException {
byte[] in = "GET /somepath%2FotherPath 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("/somepath%2FotherPath", result.getRequestURI());
Assert.assertEquals("/somepath%2FotherPath", result.getRequestPath());
}
use of io.undertow.server.HttpServerExchange in project undertow by undertow-io.
the class SimpleParserTestCase method testNoHeaders.
@Test
public void testNoHeaders() throws BadRequestException {
byte[] in = "GET /aa HTTP/1.1\n\n\n".getBytes();
final ParseState context = new ParseState(0);
HttpServerExchange result = new HttpServerExchange(null);
HttpRequestParser.instance(OptionMap.EMPTY).handle(ByteBuffer.wrap(in), context, result);
Assert.assertTrue(context.isComplete());
Assert.assertEquals("/aa", result.getRelativePath());
}
Aggregations