Search in sources :

Example 36 with HttpRequest

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

the class DiscFilterRequestTest method requireThatUnresolvableRemoteAddressesAreSupported.

@Test
public void requireThatUnresolvableRemoteAddressesAreSupported() {
    URI uri = URI.create("http://doesnotresolve.zzz:8080/test");
    HttpRequest httpReq = newRequest(uri, HttpRequest.Method.GET, HttpRequest.Version.HTTP_1_1);
    DiscFilterRequest request = new JdiscFilterRequest(httpReq);
    Assert.assertNull(request.getLocalAddr());
}
Also used : HttpRequest(com.yahoo.jdisc.http.HttpRequest) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 37 with HttpRequest

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

the class DiscFilterRequestTest method testAddCookie.

@Test
public void testAddCookie() {
    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);
    request.addCookie(JDiscCookieWrapper.wrap(new Cookie("name", "value")));
    List<Cookie> cookies = request.getCookies();
    Assert.assertEquals(cookies.size(), 1);
    Assert.assertEquals(cookies.get(0).getName(), "name");
    Assert.assertEquals(cookies.get(0).getValue(), "value");
}
Also used : HttpRequest(com.yahoo.jdisc.http.HttpRequest) Cookie(com.yahoo.jdisc.http.Cookie) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 38 with HttpRequest

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

the class DiscFilterRequestTest method testGetUntreatedHeaders.

@Test
public void testGetUntreatedHeaders() {
    URI uri = URI.create("http://example.yahoo.com/test");
    HttpRequest httpReq = newRequest(uri, HttpRequest.Method.GET, HttpRequest.Version.HTTP_1_1);
    httpReq.headers().add("key1", "value1");
    httpReq.headers().add("key2", Arrays.asList("value1", "value2"));
    DiscFilterRequest request = new JdiscFilterRequest(httpReq);
    HeaderFields headers = request.getUntreatedHeaders();
    Assert.assertEquals(headers.keySet().size(), 2);
    Assert.assertEquals(headers.get("key1").get(0), "value1");
    Assert.assertEquals(headers.get("key2").get(0), "value1");
    Assert.assertEquals(headers.get("key2").get(1), "value2");
}
Also used : HttpRequest(com.yahoo.jdisc.http.HttpRequest) HeaderFields(com.yahoo.jdisc.HeaderFields) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 39 with HttpRequest

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

the class DiscFilterRequestTest method testGetWrapedCookies.

@Test
public void testGetWrapedCookies() 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);
    JDiscCookieWrapper[] wrappers = request.getWrappedCookies();
    Assert.assertEquals(wrappers.length, 1);
    Assert.assertEquals(wrappers[0].getName(), "XYZ");
    Assert.assertEquals(wrappers[0].getValue(), "value");
}
Also used : HttpRequest(com.yahoo.jdisc.http.HttpRequest) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 40 with HttpRequest

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

the class DiscFilterRequestTest method testIsMultipart.

@Test
public void testIsMultipart() {
    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");
    DiscFilterRequest request = new JdiscFilterRequest(httpReq);
    Assert.assertEquals(true, DiscFilterRequest.isMultipart(request));
    httpReq = newRequest(uri, HttpRequest.Method.GET, HttpRequest.Version.HTTP_1_1);
    httpReq.headers().add(HttpHeaders.Names.CONTENT_TYPE, "text/html;charset=UTF-8");
    request = new JdiscFilterRequest(httpReq);
    Assert.assertEquals(DiscFilterRequest.isMultipart(request), false);
    Assert.assertEquals(DiscFilterRequest.isMultipart(null), false);
    httpReq = newRequest(uri, HttpRequest.Method.GET, HttpRequest.Version.HTTP_1_1);
    request = new JdiscFilterRequest(httpReq);
    Assert.assertEquals(DiscFilterRequest.isMultipart(request), false);
}
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