Search in sources :

Example 41 with HttpRequest

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

the class DiscFilterRequestTest method testGetServerPort.

@Test
public void testGetServerPort() throws Exception {
    URI uri = URI.create("http://example.yahoo.com/test");
    HttpRequest httpReq = newRequest(uri, HttpRequest.Method.GET, HttpRequest.Version.HTTP_1_1);
    DiscFilterRequest request = new JdiscFilterRequest(httpReq);
    Assert.assertEquals(request.getServerPort(), 80);
    request.setUri(URI.create("https://example.yahoo.com/test"));
    Assert.assertEquals(request.getServerPort(), 443);
}
Also used : HttpRequest(com.yahoo.jdisc.http.HttpRequest) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 42 with HttpRequest

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

the class DiscFilterRequestTest method testGetHeadersAsList.

@Test
public void testGetHeadersAsList() {
    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);
    Assert.assertEquals(request.getHeaderNamesAsList() instanceof List, true);
    Assert.assertEquals(request.getHeaderNamesAsList().size(), 0);
    httpReq.headers().add("header_1", "value1");
    httpReq.headers().add("header_1", "value2");
    Assert.assertEquals(request.getHeadersAsList("header_1").size(), 2);
}
Also used : HttpRequest(com.yahoo.jdisc.http.HttpRequest) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 43 with HttpRequest

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

the class DiscFilterRequestTest method testParameterAPI.

@Test
public void testParameterAPI() {
    URI uri = URI.create("http://example.yahoo.com:8080/test?param1=abc&param2=xyz&param2=pqr");
    HttpRequest httpReq = newRequest(uri, HttpRequest.Method.GET, HttpRequest.Version.HTTP_1_1);
    DiscFilterRequest request = new JdiscFilterRequest(httpReq);
    Assert.assertEquals(request.getParameter("param1"), "abc");
    Enumeration<String> values = request.getParameterValues("param2");
    List<String> valuesList = Collections.list(values);
    Assert.assertEquals(valuesList.get(0), "xyz");
    Assert.assertEquals(valuesList.get(1), "pqr");
    Enumeration<String> paramNames = request.getParameterNames();
    List<String> paramNamesList = Collections.list(paramNames);
    Assert.assertEquals(paramNamesList.size(), 2);
}
Also used : HttpRequest(com.yahoo.jdisc.http.HttpRequest) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 44 with HttpRequest

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

the class DiscFilterRequestTest method testIsSecure.

@Test
public void testIsSecure() throws Exception {
    URI uri = URI.create("http://example.yahoo.com/test");
    HttpRequest httpReq = newRequest(uri, HttpRequest.Method.GET, HttpRequest.Version.HTTP_1_1);
    DiscFilterRequest request = new JdiscFilterRequest(httpReq);
    Assert.assertEquals(request.isSecure(), false);
    request.setUri(URI.create("https://example.yahoo.com/test"));
    Assert.assertEquals(request.isSecure(), true);
}
Also used : HttpRequest(com.yahoo.jdisc.http.HttpRequest) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 45 with HttpRequest

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

the class EmptyRequestFilterTestCase method requireThatEmptyFilterDoesNothing.

@Test
public void requireThatEmptyFilterDoesNothing() throws Exception {
    final HttpRequest lhs = newRequest(Method.GET, "/status.html", Version.HTTP_1_1);
    final HttpRequest rhs = newRequest(Method.GET, "/status.html", Version.HTTP_1_1);
    EmptyRequestFilter.INSTANCE.filter(rhs, mock(ResponseHandler.class));
    assertEquals(lhs.headers(), rhs.headers());
    assertEquals(lhs.context(), rhs.context());
    assertEquals(lhs.getTimeout(TimeUnit.MILLISECONDS), rhs.getTimeout(TimeUnit.MILLISECONDS));
    assertEquals(lhs.parameters(), rhs.parameters());
    assertEquals(lhs.getMethod(), rhs.getMethod());
    assertEquals(lhs.getVersion(), rhs.getVersion());
    assertEquals(lhs.getRemoteAddress(), rhs.getRemoteAddress());
}
Also used : HttpRequest(com.yahoo.jdisc.http.HttpRequest) ResponseHandler(com.yahoo.jdisc.handler.ResponseHandler) 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