Search in sources :

Example 76 with HttpServerExchange

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());
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) UnitTest(io.undertow.testutils.category.UnitTest) Test(org.junit.Test)

Example 77 with HttpServerExchange

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());
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) UnitTest(io.undertow.testutils.category.UnitTest) Test(org.junit.Test)

Example 78 with HttpServerExchange

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" });
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) UnitTest(io.undertow.testutils.category.UnitTest) Test(org.junit.Test)

Example 79 with HttpServerExchange

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());
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) UnitTest(io.undertow.testutils.category.UnitTest) Test(org.junit.Test)

Example 80 with HttpServerExchange

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