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");
}
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");
}
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);
}
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);
}
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");
}
Aggregations