Search in sources :

Example 16 with HttpRequest

use of com.yahoo.jdisc.http.HttpRequest in project vespa by vespa-engine.

the class DiscFilterRequestTest method newRequest.

private static HttpRequest newRequest(URI uri, HttpRequest.Method method, HttpRequest.Version version) {
    InetSocketAddress address = new InetSocketAddress("example.yahoo.com", 69);
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    driver.activateContainer(driver.newContainerBuilder());
    HttpRequest request = HttpRequest.newServerRequest(driver, uri, method, version, address);
    request.release();
    assertTrue(driver.close());
    return request;
}
Also used : HttpRequest(com.yahoo.jdisc.http.HttpRequest) InetSocketAddress(java.net.InetSocketAddress) TestDriver(com.yahoo.jdisc.test.TestDriver)

Example 17 with HttpRequest

use of com.yahoo.jdisc.http.HttpRequest in project vespa by vespa-engine.

the class DiscFilterRequestTest method testCharacterEncoding.

@Test
public void testCharacterEncoding() throws Exception {
    URI uri = URI.create("http://example.yahoo.com:8080/test");
    HttpRequest httpReq = newRequest(uri, HttpRequest.Method.GET, HttpRequest.Version.HTTP_1_1);
    DiscFilterRequest request = new JdiscFilterRequest(httpReq);
    request.setHeaders(HttpHeaders.Names.CONTENT_TYPE, "text/html;charset=UTF-8");
    Assert.assertEquals(request.getCharacterEncoding(), "UTF-8");
    httpReq = newRequest(uri, HttpRequest.Method.GET, HttpRequest.Version.HTTP_1_1);
    request = new JdiscFilterRequest(httpReq);
    request.setHeaders(HttpHeaders.Names.CONTENT_TYPE, "text/html");
    request.setCharacterEncoding("UTF-8");
    Assert.assertEquals(request.getCharacterEncoding(), "UTF-8");
    Assert.assertEquals(request.getHeader(HttpHeaders.Names.CONTENT_TYPE), "text/html;charset=UTF-8");
}
Also used : HttpRequest(com.yahoo.jdisc.http.HttpRequest) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 18 with HttpRequest

use of com.yahoo.jdisc.http.HttpRequest in project vespa by vespa-engine.

the class DiscFilterRequestTest method testGetAttributeNames.

@Test
public void testGetAttributeNames() {
    URI uri = URI.create("http://localhost:8080/test");
    HttpRequest httpReq = newRequest(uri, HttpRequest.Method.GET, HttpRequest.Version.HTTP_1_1);
    DiscFilterRequest request = new JdiscFilterRequest(httpReq);
    request.setAttribute("some_attr_1", "some_value1");
    request.setAttribute("some_attr_2", "some_value2");
    Enumeration<String> e = request.getAttributeNames();
    List<String> attrList = Collections.list(e);
    Assert.assertEquals(2, attrList.size());
    Assert.assertEquals(attrList.contains("some_attr_1"), true);
    Assert.assertEquals(attrList.contains("some_attr_2"), true);
}
Also used : HttpRequest(com.yahoo.jdisc.http.HttpRequest) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 19 with HttpRequest

use of com.yahoo.jdisc.http.HttpRequest in project vespa by vespa-engine.

the class DiscFilterRequestTest method testGetRemotePortLocalPort.

@Test
public void testGetRemotePortLocalPort() {
    URI uri = URI.create("http://example.yahoo.com:8080/test");
    HttpRequest httpReq = newRequest(uri, HttpRequest.Method.GET, HttpRequest.Version.HTTP_1_1);
    DiscFilterRequest request = new JdiscFilterRequest(httpReq);
    Assert.assertEquals(69, request.getRemotePort());
    Assert.assertEquals(8080, request.getLocalPort());
    if (// if we have network
    request.getRemoteHost() != null)
        Assert.assertEquals("example.yahoo.com", request.getRemoteHost());
    request.setRemoteAddr("1.1.1.1");
    Assert.assertEquals("1.1.1.1", request.getRemoteAddr());
}
Also used : HttpRequest(com.yahoo.jdisc.http.HttpRequest) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 20 with HttpRequest

use of com.yahoo.jdisc.http.HttpRequest in project vespa by vespa-engine.

the class DiscFilterRequestTest method testRequestConstruction2.

@Test
public void testRequestConstruction2() {
    URI uri = URI.create("http://localhost:8080/test");
    HttpRequest httpReq = newRequest(uri, HttpRequest.Method.GET, HttpRequest.Version.HTTP_1_1);
    httpReq.headers().add("some-header", "some-value");
    DiscFilterRequest request = new JdiscFilterRequest(httpReq);
    request.addHeader("some-header", "some-value");
    String value = request.getUntreatedHeaders().get("some-header").get(0);
    Assert.assertEquals(value, "some-value");
}
Also used : HttpRequest(com.yahoo.jdisc.http.HttpRequest) URI(java.net.URI) Test(org.testng.annotations.Test)

Aggregations

HttpRequest (com.yahoo.jdisc.http.HttpRequest)48 Test (org.testng.annotations.Test)36 URI (java.net.URI)27 ResponseHandler (com.yahoo.jdisc.handler.ResponseHandler)7 HttpResponse (com.yahoo.jdisc.http.HttpResponse)7 RequestFilter (com.yahoo.jdisc.http.filter.RequestFilter)5 VipStatusConfig (com.yahoo.container.core.VipStatusConfig)4 BufferedContentChannel (com.yahoo.jdisc.handler.BufferedContentChannel)4 ContentChannel (com.yahoo.jdisc.handler.ContentChannel)4 Cookie (com.yahoo.jdisc.http.Cookie)4 InetSocketAddress (java.net.InetSocketAddress)4 ByteBuffer (java.nio.ByteBuffer)4 Test (org.junit.Test)4 Response (com.yahoo.jdisc.Response)2 TestDriver (com.yahoo.jdisc.test.TestDriver)2 HeaderFields (com.yahoo.jdisc.HeaderFields)1 ResourceReference (com.yahoo.jdisc.ResourceReference)1 AbstractRequestHandler (com.yahoo.jdisc.handler.AbstractRequestHandler)1 BindingNotFoundException (com.yahoo.jdisc.handler.BindingNotFoundException)1 FastContentWriter (com.yahoo.jdisc.handler.FastContentWriter)1