Search in sources :

Example 31 with HttpRequest

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

the class DiscFilterResponseTest method testSetHeader.

@Test
public void testSetHeader() {
    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);
    response.setHeader("name", "value");
    Assert.assertEquals(response.getHeader("name"), "value");
}
Also used : HttpRequest(com.yahoo.jdisc.http.HttpRequest) HttpResponse(com.yahoo.jdisc.http.HttpResponse) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 32 with HttpRequest

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

the class EmptyResponseFilterTestCase method requireThatEmptyFilterDoesNothing.

@Test
public void requireThatEmptyFilterDoesNothing() throws Exception {
    final HttpRequest request = newRequest(Method.GET, "/status.html", Version.HTTP_1_1);
    final HttpResponse lhs = HttpResponse.newInstance(Response.Status.OK);
    final HttpResponse rhs = HttpResponse.newInstance(Response.Status.OK);
    EmptyResponseFilter.INSTANCE.filter(lhs, null);
    assertEquals(lhs.headers(), rhs.headers());
    assertEquals(lhs.context(), rhs.context());
    assertEquals(lhs.getError(), rhs.getError());
    assertEquals(lhs.getMessage(), rhs.getMessage());
}
Also used : HttpRequest(com.yahoo.jdisc.http.HttpRequest) HttpResponse(com.yahoo.jdisc.http.HttpResponse) Test(org.testng.annotations.Test)

Example 33 with HttpRequest

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

the class HttpRequestFactoryTest method test.

@Test
public final void test() {
    String noise = "query=a" + "\\" + "^{|}&other=madeit";
    HttpServletRequest servletRequest = new MockRequest("http://yahoo.com/search?" + noise);
    HttpRequest request = HttpRequestFactory.newJDiscRequest(new MockContainer(), servletRequest);
    assertThat(request.getUri().getQuery(), equalTo(noise));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpRequest(com.yahoo.jdisc.http.HttpRequest) Test(org.testng.annotations.Test)

Example 34 with HttpRequest

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

the class HttpRequestFactory method newJDiscRequest.

public static HttpRequest newJDiscRequest(CurrentContainer container, HttpServletRequest servletRequest) {
    HttpRequest httpRequest = HttpRequest.newServerRequest(container, getUri(servletRequest), HttpRequest.Method.valueOf(servletRequest.getMethod()), HttpRequest.Version.fromString(servletRequest.getProtocol()), new InetSocketAddress(servletRequest.getRemoteAddr(), servletRequest.getRemotePort()), getConnection(servletRequest).getCreatedTimeStamp());
    httpRequest.context().put(ServletRequest.JDISC_REQUEST_X509CERT, getCertChain(servletRequest));
    return httpRequest;
}
Also used : HttpRequest(com.yahoo.jdisc.http.HttpRequest) InetSocketAddress(java.net.InetSocketAddress)

Example 35 with HttpRequest

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

the class DiscFilterRequestTest method testGetHeaderNamesAsList.

@Test
public void testGetHeaderNamesAsList() {
    URI uri = URI.create("http://localhost:8080/test");
    HttpRequest httpReq = newRequest(uri, HttpRequest.Method.GET, HttpRequest.Version.HTTP_1_1);
    httpReq.headers().add(HttpHeaders.Names.CONTENT_TYPE, "multipart/form-data");
    httpReq.headers().add("header_1", "value1");
    httpReq.headers().add("header_2", "value2");
    DiscFilterRequest request = new JdiscFilterRequest(httpReq);
    Assert.assertEquals(request.getHeaderNamesAsList() instanceof List, true);
    Assert.assertEquals(request.getHeaderNamesAsList().size(), 3);
}
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