Search in sources :

Example 1 with HttpResponse

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

the class DiscFilterResponseTest method testAddCookie.

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

Example 2 with HttpResponse

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

the class DiscFilterResponseTest method testSetCookie.

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

Example 3 with HttpResponse

use of com.yahoo.jdisc.http.HttpResponse 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 4 with HttpResponse

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

the class AccessControlRequestFilter method filter.

@Override
public void filter(DiscFilterRequest discFilterRequest, ResponseHandler responseHandler) {
    String origin = discFilterRequest.getHeader("Origin");
    if (!discFilterRequest.getMethod().equals(OPTIONS.name()))
        return;
    HttpResponse response = HttpResponse.newInstance(Response.Status.OK);
    if (allowedUrls.contains(origin))
        response.headers().add(ALLOW_ORIGIN_HEADER, origin);
    ACCESS_CONTROL_HEADERS.forEach((name, value) -> response.headers().add(name, value));
    ContentChannel cc = responseHandler.handleResponse(response);
    cc.close(null);
}
Also used : ContentChannel(com.yahoo.jdisc.handler.ContentChannel) HttpResponse(com.yahoo.jdisc.http.HttpResponse)

Example 5 with HttpResponse

use of com.yahoo.jdisc.http.HttpResponse 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)

Aggregations

HttpResponse (com.yahoo.jdisc.http.HttpResponse)6 HttpRequest (com.yahoo.jdisc.http.HttpRequest)5 Test (org.testng.annotations.Test)5 URI (java.net.URI)4 Cookie (com.yahoo.jdisc.http.Cookie)2 ContentChannel (com.yahoo.jdisc.handler.ContentChannel)1