use of com.yahoo.jdisc.http.HttpRequest in project vespa by vespa-engine.
the class DiscFilterRequestTest method newRequest.
private static HttpRequest newRequest(URI uri, HttpRequest.Method method, HttpRequest.Version version) {
InetSocketAddress address = new InetSocketAddress("example.yahoo.com", 69);
TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
driver.activateContainer(driver.newContainerBuilder());
HttpRequest request = HttpRequest.newServerRequest(driver, uri, method, version, address);
request.release();
assertTrue(driver.close());
return request;
}
use of com.yahoo.jdisc.http.HttpRequest in project vespa by vespa-engine.
the class DiscFilterRequestTest method testCharacterEncoding.
@Test
public void testCharacterEncoding() throws Exception {
URI uri = URI.create("http://example.yahoo.com:8080/test");
HttpRequest httpReq = newRequest(uri, HttpRequest.Method.GET, HttpRequest.Version.HTTP_1_1);
DiscFilterRequest request = new JdiscFilterRequest(httpReq);
request.setHeaders(HttpHeaders.Names.CONTENT_TYPE, "text/html;charset=UTF-8");
Assert.assertEquals(request.getCharacterEncoding(), "UTF-8");
httpReq = newRequest(uri, HttpRequest.Method.GET, HttpRequest.Version.HTTP_1_1);
request = new JdiscFilterRequest(httpReq);
request.setHeaders(HttpHeaders.Names.CONTENT_TYPE, "text/html");
request.setCharacterEncoding("UTF-8");
Assert.assertEquals(request.getCharacterEncoding(), "UTF-8");
Assert.assertEquals(request.getHeader(HttpHeaders.Names.CONTENT_TYPE), "text/html;charset=UTF-8");
}
use of com.yahoo.jdisc.http.HttpRequest in project vespa by vespa-engine.
the class DiscFilterRequestTest method testGetAttributeNames.
@Test
public void testGetAttributeNames() {
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_1", "some_value1");
request.setAttribute("some_attr_2", "some_value2");
Enumeration<String> e = request.getAttributeNames();
List<String> attrList = Collections.list(e);
Assert.assertEquals(2, attrList.size());
Assert.assertEquals(attrList.contains("some_attr_1"), true);
Assert.assertEquals(attrList.contains("some_attr_2"), true);
}
use of com.yahoo.jdisc.http.HttpRequest in project vespa by vespa-engine.
the class DiscFilterRequestTest method testGetRemotePortLocalPort.
@Test
public void testGetRemotePortLocalPort() {
URI uri = URI.create("http://example.yahoo.com:8080/test");
HttpRequest httpReq = newRequest(uri, HttpRequest.Method.GET, HttpRequest.Version.HTTP_1_1);
DiscFilterRequest request = new JdiscFilterRequest(httpReq);
Assert.assertEquals(69, request.getRemotePort());
Assert.assertEquals(8080, request.getLocalPort());
if (// if we have network
request.getRemoteHost() != null)
Assert.assertEquals("example.yahoo.com", request.getRemoteHost());
request.setRemoteAddr("1.1.1.1");
Assert.assertEquals("1.1.1.1", request.getRemoteAddr());
}
use of com.yahoo.jdisc.http.HttpRequest in project vespa by vespa-engine.
the class DiscFilterRequestTest method testRequestConstruction2.
@Test
public void testRequestConstruction2() {
URI uri = URI.create("http://localhost:8080/test");
HttpRequest httpReq = newRequest(uri, HttpRequest.Method.GET, HttpRequest.Version.HTTP_1_1);
httpReq.headers().add("some-header", "some-value");
DiscFilterRequest request = new JdiscFilterRequest(httpReq);
request.addHeader("some-header", "some-value");
String value = request.getUntreatedHeaders().get("some-header").get(0);
Assert.assertEquals(value, "some-value");
}
Aggregations