Search in sources :

Example 6 with HttpRequest

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

the class DiscFilterResponseTest method testAddHeader.

@Test
public void testAddHeader() {
    HttpRequest request = newRequest(URI.create("http://localhost:8080/echo"), HttpRequest.Method.GET, HttpRequest.Version.HTTP_1_1);
    DiscFilterResponse response = new JdiscFilterResponse(HttpResponse.newInstance(HttpResponse.Status.OK));
    response.addHeader("header1", "value1");
    Assert.assertEquals(response.getHeader("header1"), "value1");
}
Also used : HttpRequest(com.yahoo.jdisc.http.HttpRequest) Test(org.testng.annotations.Test)

Example 7 with HttpRequest

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

the class DiscFilterResponseTest method testAttributes.

@Test
public void testAttributes() {
    HttpRequest request = newRequest(URI.create("http://localhost:8080/echo"), HttpRequest.Method.GET, HttpRequest.Version.HTTP_1_1);
    DiscFilterResponse response = new JdiscFilterResponse(HttpResponse.newInstance(HttpResponse.Status.OK));
    response.setAttribute("attr_1", "value1");
    Assert.assertEquals(response.getAttribute("attr_1"), "value1");
    List<String> list = Collections.list(response.getAttributeNames());
    Assert.assertEquals(list.get(0), "attr_1");
    response.removeAttribute("attr_1");
    Assert.assertNull(response.getAttribute("attr_1"));
}
Also used : HttpRequest(com.yahoo.jdisc.http.HttpRequest) Test(org.testng.annotations.Test)

Example 8 with HttpRequest

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

the class DiscFilterResponseTest method testGetSetStatus.

@Test
public void testGetSetStatus() {
    HttpRequest request = newRequest(URI.create("http://localhost:8080/echo"), HttpRequest.Method.GET, HttpRequest.Version.HTTP_1_1);
    DiscFilterResponse response = new JdiscFilterResponse(HttpResponse.newInstance(HttpResponse.Status.OK));
    Assert.assertEquals(response.getStatus(), HttpResponse.Status.OK);
    response.setStatus(HttpResponse.Status.REQUEST_TIMEOUT);
    Assert.assertEquals(response.getStatus(), HttpResponse.Status.REQUEST_TIMEOUT);
}
Also used : HttpRequest(com.yahoo.jdisc.http.HttpRequest) Test(org.testng.annotations.Test)

Example 9 with HttpRequest

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

the class DiscFilterResponseTest method testGetParentResponse.

@Test
public void testGetParentResponse() {
    URI uri = URI.create("http://example.com/test");
    HttpRequest httpReq = newRequest(uri, HttpRequest.Method.GET, HttpRequest.Version.HTTP_1_1);
    HttpResponse httpResp = newResponse(httpReq, 200);
    DiscFilterResponse response = new JdiscFilterResponse(httpResp);
    Assert.assertSame(response.getParentResponse(), httpResp);
}
Also used : HttpRequest(com.yahoo.jdisc.http.HttpRequest) HttpResponse(com.yahoo.jdisc.http.HttpResponse) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 10 with HttpRequest

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

the class FilterTestCase method requireThatRequestFilterCanTerminateChain.

@Test
public void requireThatRequestFilterCanTerminateChain() throws Exception {
    final RequestFilter requestFilter1 = new RespondForbiddenFilter();
    final RequestFilter requestFilter2 = mock(RequestFilter.class);
    final RequestFilter requestFilterChain = RequestFilterChain.newInstance(requestFilter1, requestFilter2);
    final HttpRequest request = null;
    final ResponseHandler responseHandler = mock(ResponseHandler.class);
    when(responseHandler.handleResponse(any(Response.class))).thenReturn(mock(ContentChannel.class));
    requestFilterChain.filter(request, responseHandler);
    verify(requestFilter2, never()).filter(any(HttpRequest.class), any(ResponseHandler.class));
    final ArgumentCaptor<Response> responseCaptor = ArgumentCaptor.forClass(Response.class);
    verify(responseHandler).handleResponse(responseCaptor.capture());
    assertThat(responseCaptor.getValue().getStatus(), is(Response.Status.FORBIDDEN));
}
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) ContentChannel(com.yahoo.jdisc.handler.ContentChannel) RequestFilter(com.yahoo.jdisc.http.filter.RequestFilter) 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