Search in sources :

Example 11 with HttpRequest

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

the class FilterTestCase method requireThatRequestFilterChainCallsFilterWithOriginalResponseHandler.

@Test
public void requireThatRequestFilterChainCallsFilterWithOriginalResponseHandler() throws Exception {
    final RequestFilter requestFilter = mock(RequestFilter.class);
    final RequestFilter requestFilterChain = RequestFilterChain.newInstance(requestFilter);
    final HttpRequest request = null;
    final ResponseHandler responseHandler = mock(ResponseHandler.class);
    requestFilterChain.filter(request, responseHandler);
    // Check that the filter is called with the same response handler argument as the chain was,
    // in a manner that allows the handler object to be wrapped.
    final ArgumentCaptor<ResponseHandler> responseHandlerCaptor = ArgumentCaptor.forClass(ResponseHandler.class);
    verify(requestFilter).filter(any(HttpRequest.class), responseHandlerCaptor.capture());
    verify(responseHandler, never()).handleResponse(any(Response.class));
    responseHandlerCaptor.getValue().handleResponse(mock(Response.class));
    verify(responseHandler, times(1)).handleResponse(any(Response.class));
}
Also used : HttpRequest(com.yahoo.jdisc.http.HttpRequest) HttpResponse(com.yahoo.jdisc.http.HttpResponse) Response(com.yahoo.jdisc.Response) ResponseHandler(com.yahoo.jdisc.handler.ResponseHandler) RequestFilter(com.yahoo.jdisc.http.filter.RequestFilter) Test(org.testng.annotations.Test)

Example 12 with HttpRequest

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

the class FilterTestCase method requireThatRequestFilterChainCallsFilterWithOriginalRequest.

@Test
public void requireThatRequestFilterChainCallsFilterWithOriginalRequest() throws Exception {
    final RequestFilter requestFilter = mock(RequestFilter.class);
    final RequestFilter requestFilterChain = RequestFilterChain.newInstance(requestFilter);
    final HttpRequest request = mock(HttpRequest.class);
    final ResponseHandler responseHandler = null;
    requestFilterChain.filter(request, responseHandler);
    // Check that the filter is called with the same request argument as the chain was,
    // in a manner that allows the request object to be wrapped.
    final ArgumentCaptor<HttpRequest> requestCaptor = ArgumentCaptor.forClass(HttpRequest.class);
    verify(requestFilter).filter(requestCaptor.capture(), any(ResponseHandler.class));
    verify(request, never()).getUri();
    requestCaptor.getValue().getUri();
    verify(request, times(1)).getUri();
}
Also used : HttpRequest(com.yahoo.jdisc.http.HttpRequest) ResponseHandler(com.yahoo.jdisc.handler.ResponseHandler) RequestFilter(com.yahoo.jdisc.http.filter.RequestFilter) Test(org.testng.annotations.Test)

Example 13 with HttpRequest

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

the class DiscFilterRequestTest method testRemoveAttribute.

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

Example 14 with HttpRequest

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

the class DiscFilterRequestTest method testGetIntHeader.

@Test
public void testGetIntHeader() {
    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.getIntHeader("int_header"));
    request.addHeader("int_header", String.valueOf(5));
    Assert.assertEquals(5, request.getIntHeader("int_header"));
}
Also used : HttpRequest(com.yahoo.jdisc.http.HttpRequest) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 15 with HttpRequest

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

the class DiscFilterRequestTest method testClearCookies.

@Test
public void testClearCookies() throws Exception {
    URI uri = URI.create("http://example.yahoo.com/test");
    HttpRequest httpReq = newRequest(uri, HttpRequest.Method.GET, HttpRequest.Version.HTTP_1_1);
    httpReq.headers().put(HttpHeaders.Names.COOKIE, "XYZ=value");
    DiscFilterRequest request = new JdiscFilterRequest(httpReq);
    request.clearCookies();
    Assert.assertNull(request.getHeader(HttpHeaders.Names.COOKIE));
}
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