use of com.yahoo.jdisc.http.HttpRequest in project vespa by vespa-engine.
the class DiscFilterRequestTest method testSetScheme.
@Test
public void testSetScheme() throws Exception {
URI uri = URI.create("https://example.yahoo.com:8080/test");
HttpRequest httpReq = newRequest(uri, HttpRequest.Method.GET, HttpRequest.Version.HTTP_1_1);
DiscFilterRequest request = new JdiscFilterRequest(httpReq);
request.setScheme("http", true);
System.out.println(request.getUri().toString());
Assert.assertEquals(request.getUri().toString(), "http://example.yahoo.com:8080/test");
}
use of com.yahoo.jdisc.http.HttpRequest in project vespa by vespa-engine.
the class DiscFilterRequestTest method testRequestAttributes.
@Test
public void testRequestAttributes() {
URI uri = URI.create("http://localhost:8080/test");
HttpRequest httpReq = newRequest(uri, HttpRequest.Method.GET, HttpRequest.Version.HTTP_1_1);
DiscFilterRequest request = new JdiscFilterRequest(httpReq);
request.setAttribute("some_attr", "some_value");
Assert.assertEquals(request.containsAttribute("some_attr"), true);
Assert.assertEquals(request.getAttribute("some_attr"), "some_value");
}
use of com.yahoo.jdisc.http.HttpRequest in project vespa by vespa-engine.
the class DiscFilterRequestTest method testDateHeader.
@Test
public void testDateHeader() {
URI uri = URI.create("http://localhost:8080/test");
HttpRequest httpReq = newRequest(uri, HttpRequest.Method.GET, HttpRequest.Version.HTTP_1_1);
DiscFilterRequest request = new JdiscFilterRequest(httpReq);
Assert.assertEquals(-1, request.getDateHeader(HttpHeaders.Names.IF_MODIFIED_SINCE));
request.addHeader(HttpHeaders.Names.IF_MODIFIED_SINCE, "Sat, 29 Oct 1994 19:43:31 GMT");
Assert.assertEquals(783459811000L, request.getDateHeader(HttpHeaders.Names.IF_MODIFIED_SINCE));
}
use of com.yahoo.jdisc.http.HttpRequest in project vespa by vespa-engine.
the class DiscFilterRequestTest method testParameterAPIsAsList.
@Test
public void testParameterAPIsAsList() {
URI uri = URI.create("http://example.yahoo.com:8080/test?param1=abc¶m2=xyz¶m2=pqr");
HttpRequest httpReq = newRequest(uri, HttpRequest.Method.GET, HttpRequest.Version.HTTP_1_1);
DiscFilterRequest request = new JdiscFilterRequest(httpReq);
Assert.assertEquals(request.getParameter("param1"), "abc");
List<String> values = request.getParameterValuesAsList("param2");
Assert.assertEquals(values.get(0), "xyz");
Assert.assertEquals(values.get(1), "pqr");
List<String> paramNames = request.getParameterNamesAsList();
Assert.assertEquals(paramNames.size(), 2);
}
use of com.yahoo.jdisc.http.HttpRequest in project vespa by vespa-engine.
the class DiscFilterRequestTest method testRequestConstruction.
@Test
public void testRequestConstruction() {
URI uri = URI.create("http://localhost:8080/test?param1=abc");
HttpRequest httpReq = newRequest(uri, HttpRequest.Method.GET, HttpRequest.Version.HTTP_1_1);
httpReq.headers().add(HttpHeaders.Names.CONTENT_TYPE, "text/html;charset=UTF-8");
httpReq.headers().add("X-Custom-Header", "custom_header");
List<Cookie> cookies = new ArrayList<Cookie>();
cookies.add(new Cookie("XYZ", "value"));
cookies.add(new Cookie("ABC", "value"));
httpReq.encodeCookieHeader(cookies);
DiscFilterRequest request = new JdiscFilterRequest(httpReq);
Assert.assertSame(request.getParentRequest(), httpReq);
Assert.assertEquals(request.getHeader("X-Custom-Header"), "custom_header");
Assert.assertEquals(request.getHeader(HttpHeaders.Names.CONTENT_TYPE), "text/html;charset=UTF-8");
List<Cookie> c = request.getCookies();
Assert.assertNotNull(c);
Assert.assertEquals(c.size(), 2);
Assert.assertEquals(request.getParameter("param1"), "abc");
Assert.assertNull(request.getParameter("param2"));
Assert.assertEquals(request.getVersion(), Version.HTTP_1_1);
Assert.assertEquals(request.getProtocol(), Version.HTTP_1_1.name());
Assert.assertNull(request.getRequestedSessionId());
}
Aggregations