use of io.undertow.server.HttpServerExchange in project undertow by undertow-io.
the class AjpParsingUnitTestCase method testInvalidQueryString.
@Test
public void testInvalidQueryString() throws Exception {
ByteBuffer data = createAjpRequest("/hi".getBytes(StandardCharsets.UTF_8), "param=value%http".getBytes(StandardCharsets.UTF_8));
HttpServerExchange result = new HttpServerExchange(null);
AjpRequestParseState state = new AjpRequestParseState();
AJP_REQUEST_PARSER.parse(data, state, result);
Assert.assertTrue(state.badRequest);
}
use of io.undertow.server.HttpServerExchange in project undertow by undertow-io.
the class AjpParsingUnitTestCase method testByteByByteAjpParsing.
@Test
public void testByteByByteAjpParsing() throws IOException, BadRequestException {
final ByteBuffer buffer = AjpParsingUnitTestCase.buffer.duplicate();
HttpServerExchange result = new HttpServerExchange(null);
final AjpRequestParseState state = new AjpRequestParseState();
int limit = buffer.limit();
for (int i = 1; i <= limit; ++i) {
buffer.limit(i);
AJP_REQUEST_PARSER.parse(buffer, state, result);
}
Assert.assertEquals(165, state.dataSize);
Assert.assertTrue(state.isComplete());
testResult(result);
}
use of io.undertow.server.HttpServerExchange in project undertow by undertow-io.
the class AjpParsingUnitTestCase method testCharsetHandling.
@Test
public void testCharsetHandling() throws Exception {
ByteBuffer data = createAjpRequest("/hi".getBytes(StandardCharsets.UTF_8), "param=value".getBytes(StandardCharsets.UTF_8));
HttpServerExchange result = new HttpServerExchange(null);
AjpRequestParseState state = new AjpRequestParseState();
AJP_REQUEST_PARSER.parse(data, state, result);
Assert.assertFalse(state.badRequest);
Assert.assertEquals("/hi", result.getRequestPath());
Assert.assertEquals("/hi", result.getRequestURI());
Assert.assertEquals("param=value", result.getQueryString());
data = createAjpRequest("/한글이름".getBytes(StandardCharsets.UTF_8), "param=한글이름".getBytes(StandardCharsets.UTF_8));
result = new HttpServerExchange(null);
state = new AjpRequestParseState();
AJP_REQUEST_PARSER.parse(data, state, result);
Assert.assertFalse(state.badRequest);
Assert.assertEquals("/한글이름", result.getRequestPath());
Assert.assertEquals("/한글이름", result.getRequestURI());
Assert.assertEquals("param=한글이름", result.getQueryString());
}
use of io.undertow.server.HttpServerExchange in project undertow by undertow-io.
the class AjpParsingUnitTestCase method testPathParamMatrixQueryString.
@Test
public void testPathParamMatrixQueryString() throws Exception {
ByteBuffer data = createAjpRequest("/hi1;path1=param1;path2=param2/hi2;path3=param3/hi3/hi4/hi5;path4=param4;path5=param5/hi6".getBytes(StandardCharsets.UTF_8), "param=value".getBytes(StandardCharsets.UTF_8));
HttpServerExchange result = new HttpServerExchange(null);
AjpRequestParseState state = new AjpRequestParseState();
AJP_REQUEST_PARSER.parse(data, state, result);
Assert.assertFalse(state.badRequest);
Assert.assertEquals("/hi1/hi2/hi3/hi4/hi5/hi6", result.getRequestPath());
Assert.assertEquals("/hi1;path1=param1;path2=param2/hi2;path3=param3/hi3/hi4/hi5;path4=param4;path5=param5/hi6", result.getRequestURI());
Assert.assertEquals("param=value", result.getQueryString());
Map<String, Deque<String>> paramsMap = result.getPathParameters();
Assert.assertNotNull(paramsMap);
Assert.assertEquals(5, paramsMap.size());
assertPathParamValue(paramsMap, "path1", "param1");
assertPathParamValue(paramsMap, "path2", "param2");
assertPathParamValue(paramsMap, "path3", "param3");
assertPathParamValue(paramsMap, "path4", "param4");
assertPathParamValue(paramsMap, "path5", "param5");
}
use of io.undertow.server.HttpServerExchange in project undertow by undertow-io.
the class ParserResumeTestCase method testOneCharacterAtATime.
@Test
public void testOneCharacterAtATime() throws BadRequestException {
context.reset();
byte[] in = DATA.getBytes();
HttpServerExchange result = new HttpServerExchange(null);
ByteBuffer buffer = ByteBuffer.wrap(in);
int oldLimit = buffer.limit();
buffer.limit(1);
while (context.state != ParseState.PARSE_COMPLETE) {
PARSER.handle(buffer, context, result);
if (context.state != ParseState.PARSE_COMPLETE) {
buffer.limit(buffer.limit() + 1);
}
}
Assert.assertEquals(oldLimit, buffer.limit() + 4);
runAssertions(result);
}
Aggregations