use of com.hotels.styx.api.HttpRequest in project styx by ExpediaGroup.
the class UrlRequestHealthCheck method check.
@Override
public void check(HttpClient client, Origin origin, OriginHealthCheckFunction.Callback responseCallback) {
HttpRequest request = newHealthCheckRequestFor(origin);
client.send(request).handle((response, cause) -> {
if (response != null) {
if (response.status().equals(OK)) {
responseCallback.originStateResponse(HEALTHY);
} else {
meterCache.get(origin).increment();
responseCallback.originStateResponse(UNHEALTHY);
}
} else if (cause != null) {
meterCache.get(origin).increment();
responseCallback.originStateResponse(UNHEALTHY);
}
return null;
});
}
use of com.hotels.styx.api.HttpRequest in project styx by ExpediaGroup.
the class UrlPatternRouter method handle.
@Override
public Eventual<HttpResponse> handle(HttpRequest request, HttpInterceptor.Context context) {
for (RouteDescriptor route : alternatives) {
if (request.method().equals(route.method())) {
Matcher match = route.uriPattern().matcher(request.path());
LOGGER.debug("Request path '{}' matching against route pattern '{}' matches: {}", new Object[] { request.path(), route.uriPattern(), match.matches() });
if (match.matches()) {
Map<String, String> placeholders = route.placeholderNames().stream().collect(toMap(name -> name, match::group));
context.add(PLACEHOLDERS_KEY, placeholders);
try {
return route.handler().handle(request, context);
} catch (Exception cause) {
LOGGER.error("ERROR: {} {}", new Object[] { request.method(), request.path(), cause });
return Eventual.of(response(INTERNAL_SERVER_ERROR).build());
}
}
}
}
return Eventual.of(response(NOT_FOUND).build());
}
use of com.hotels.styx.api.HttpRequest in project styx by ExpediaGroup.
the class HttpMethodFilteringHandlerTest method failsIfRequestMethodIsNotSupported.
@Test
public void failsIfRequestMethodIsNotSupported() throws Exception {
WebServiceHandler handler = mock(WebServiceHandler.class);
HttpMethodFilteringHandler post = new HttpMethodFilteringHandler(GET, handler);
HttpRequest request = post("/some-uri").build();
HttpResponse response = Mono.from(post.handle(request, requestContext())).block();
assertThat(response.status(), is(METHOD_NOT_ALLOWED));
}
use of com.hotels.styx.api.HttpRequest in project styx by ExpediaGroup.
the class StaticFileOnRealServerIT method shouldWorkInRealServer.
@Test
public void shouldWorkInRealServer() throws Exception {
writeFile("index.html", "Hello World");
writeFile("foo.js", "some js");
mkdir("some/dir");
writeFile("some/dir/content1.txt", "some txt");
HttpRequest request = new HttpRequest.Builder(GET, "/index.html").header("Host", serverEndpoint).build();
HttpResponse response = await(client.sendRequest(request));
assertThat(response.bodyAs(UTF_8), is("Hello World"));
}
use of com.hotels.styx.api.HttpRequest in project styx by ExpediaGroup.
the class ProtocolMetricsTest method doRequest.
private static HttpResponse doRequest(HttpClient client, String protocol, int port, String path) {
String url = format("%s://localhost:%s%s", protocol, port, startWithSlash(path));
HttpRequest request = get(url).body("foobarbaz", UTF_8).build();
return await(client.sendRequest(request));
}
Aggregations