Search in sources :

Example 21 with HttpRequest

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

the class DiscFilterRequestTest method testSetScheme.

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

Example 22 with HttpRequest

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

the class DiscFilterRequestTest method testRequestAttributes.

@Test
public void testRequestAttributes() {
    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", "some_value");
    Assert.assertEquals(request.containsAttribute("some_attr"), true);
    Assert.assertEquals(request.getAttribute("some_attr"), "some_value");
}
Also used : HttpRequest(com.yahoo.jdisc.http.HttpRequest) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 23 with HttpRequest

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

the class DiscFilterRequestTest method testDateHeader.

@Test
public void testDateHeader() {
    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(-1, request.getDateHeader(HttpHeaders.Names.IF_MODIFIED_SINCE));
    request.addHeader(HttpHeaders.Names.IF_MODIFIED_SINCE, "Sat, 29 Oct 1994 19:43:31 GMT");
    Assert.assertEquals(783459811000L, request.getDateHeader(HttpHeaders.Names.IF_MODIFIED_SINCE));
}
Also used : HttpRequest(com.yahoo.jdisc.http.HttpRequest) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 24 with HttpRequest

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

the class DiscFilterRequestTest method testParameterAPIsAsList.

@Test
public void testParameterAPIsAsList() {
    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");
    List<String> values = request.getParameterValuesAsList("param2");
    Assert.assertEquals(values.get(0), "xyz");
    Assert.assertEquals(values.get(1), "pqr");
    List<String> paramNames = request.getParameterNamesAsList();
    Assert.assertEquals(paramNames.size(), 2);
}
Also used : HttpRequest(com.yahoo.jdisc.http.HttpRequest) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 25 with HttpRequest

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

the class DiscFilterRequestTest method testRequestConstruction.

@Test
public void testRequestConstruction() {
    URI uri = URI.create("http://localhost:8080/test?param1=abc");
    HttpRequest httpReq = newRequest(uri, HttpRequest.Method.GET, HttpRequest.Version.HTTP_1_1);
    httpReq.headers().add(HttpHeaders.Names.CONTENT_TYPE, "text/html;charset=UTF-8");
    httpReq.headers().add("X-Custom-Header", "custom_header");
    List<Cookie> cookies = new ArrayList<Cookie>();
    cookies.add(new Cookie("XYZ", "value"));
    cookies.add(new Cookie("ABC", "value"));
    httpReq.encodeCookieHeader(cookies);
    DiscFilterRequest request = new JdiscFilterRequest(httpReq);
    Assert.assertSame(request.getParentRequest(), httpReq);
    Assert.assertEquals(request.getHeader("X-Custom-Header"), "custom_header");
    Assert.assertEquals(request.getHeader(HttpHeaders.Names.CONTENT_TYPE), "text/html;charset=UTF-8");
    List<Cookie> c = request.getCookies();
    Assert.assertNotNull(c);
    Assert.assertEquals(c.size(), 2);
    Assert.assertEquals(request.getParameter("param1"), "abc");
    Assert.assertNull(request.getParameter("param2"));
    Assert.assertEquals(request.getVersion(), Version.HTTP_1_1);
    Assert.assertEquals(request.getProtocol(), Version.HTTP_1_1.name());
    Assert.assertNull(request.getRequestedSessionId());
}
Also used : HttpRequest(com.yahoo.jdisc.http.HttpRequest) Cookie(com.yahoo.jdisc.http.Cookie) 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