use of io.airlift.http.client.StringResponseHandler.StringResponse in project airlift by airlift.
the class TestHttpServerProvider method assertForward.
private void assertForward(ForwardedServlet servlet, Optional<String> proto, Optional<String> host, Optional<String> remoteHost) {
servlet.reset();
HttpUriBuilder uriBuilder = HttpUriBuilder.uriBuilderFrom(httpServerInfo.getHttpUri()).replacePath("/some/path");
try (HttpClient client = new JettyHttpClient()) {
Builder builder = prepareGet().setUri(uriBuilder.build());
proto.ifPresent(value -> builder.addHeader(X_FORWARDED_PROTO, value));
host.ifPresent(value -> builder.addHeader(X_FORWARDED_HOST, value));
remoteHost.ifPresent(value -> builder.addHeader(X_FORWARDED_FOR, value));
StringResponse response = client.execute(builder.build(), createStringResponseHandler());
assertEquals(response.getStatusCode(), 200);
}
proto.ifPresent(uriBuilder::scheme);
host.map(HostAndPort::fromString).ifPresent(uriBuilder::hostAndPort);
URI forwardedUri = uriBuilder.build();
assertEquals(servlet.getRequestUrl(), forwardedUri.toString());
assertEquals(servlet.getScheme(), forwardedUri.getScheme());
assertEquals(servlet.getIsSecure(), (Boolean) forwardedUri.getScheme().equals("https"));
remoteHost.ifPresent(value -> assertEquals(servlet.getRemoteAddress(), value));
}
use of io.airlift.http.client.StringResponseHandler.StringResponse in project airlift by airlift.
the class TestJaxrsTestingHttpProcessor method testOptions.
@Test
public void testOptions() {
Request request = new Request.Builder().setMethod("OPTIONS").setUri(URI.create("http://fake.invalid/get-it/get/xyz")).build();
StringResponse response = HTTP_CLIENT.execute(request, createStringResponseHandler());
assertThat(response.getStatusCode()).isEqualTo(HTTP_OK);
assertThat(response.getHeader(CONTENT_TYPE)).isEqualTo("application/vnd.sun.wadl+xml");
assertThat(response.getBody()).startsWith("<?xml ").contains("<application ");
}
use of io.airlift.http.client.StringResponseHandler.StringResponse in project airlift by airlift.
the class TestJaxrsTestingHttpProcessor method test.
@Test
public void test() {
Request request = prepareGet().setUri(URI.create("http://fake.invalid/get-it/get/xyz")).setHeader("X-Test", "abc").build();
StringResponse response = HTTP_CLIENT.execute(request, createStringResponseHandler());
assertEquals(response.getStatusCode(), HttpStatus.OK.code());
assertEquals(response.getBody(), "Got xyz");
assertEquals(response.getHeader("X-Test-Out"), "Got abc");
}
use of io.airlift.http.client.StringResponseHandler.StringResponse in project airlift by airlift.
the class TestMBeanResource method jsonRequest.
private JsonNode jsonRequest(URI uri) throws IOException {
Request request = prepareGet().setUri(uri).build();
StringResponse response = client.execute(request, createStringResponseHandler());
assertEquals(response.getStatusCode(), 200, response.getBody());
assertContentType(response, JSON_UTF_8);
return new ObjectMapperProvider().get().readTree(response.getBody());
}
use of io.airlift.http.client.StringResponseHandler.StringResponse in project airlift by airlift.
the class TestMBeanResource method jsonpRequest.
private JsonNode jsonpRequest(URI uri) throws IOException {
uri = uriBuilderFrom(uri).addParameter("jsonp", "test").build();
Request request = prepareGet().setUri(uri).build();
StringResponse response = client.execute(request, createStringResponseHandler());
assertEquals(response.getStatusCode(), 200, response.getBody());
assertContentType(response, JSON_UTF_8);
String jsonp = response.getBody().trim();
assertTrue(jsonp.startsWith("test("), jsonp);
assertTrue(jsonp.endsWith(")"), jsonp);
jsonp = jsonp.substring(5, jsonp.length() - 1);
return new ObjectMapperProvider().get().readTree(jsonp);
}
Aggregations