use of com.hotels.styx.api.HttpHandler in project styx by ExpediaGroup.
the class StandardHttpPipelineTest method sendsExceptionUponMultipleSubscription.
@Test
public void sendsExceptionUponMultipleSubscription() {
HttpHandler handler = (request, context) -> Eventual.of(response(OK).build());
StandardHttpPipeline pipeline = new StandardHttpPipeline(handler);
Eventual<LiveHttpResponse> responseObservable = pipeline.handle(get("/").build(), requestContext());
LiveHttpResponse response = Mono.from(responseObservable).block();
assertThat(response.status(), is(OK));
assertThrows(IllegalStateException.class, () -> Mono.from(responseObservable).block());
}
use of com.hotels.styx.api.HttpHandler in project styx by ExpediaGroup.
the class StaticPipelineBuilderTest method appliesPluginsInOrderTheyAreConfigured.
@Test
public void appliesPluginsInOrderTheyAreConfigured() throws Exception {
Iterable<NamedPlugin> plugins = List.of(interceptor("Test-A", appendResponseHeader("X-From-Plugin", "A")), interceptor("Test-B", appendResponseHeader("X-From-Plugin", "B")));
HttpHandler handler = new StaticPipelineFactory(clientFactory, environment, registry, plugins, executor, false).build();
LiveHttpResponse response = Mono.from(handler.handle(get("/foo").build(), requestContext())).block();
assertThat(response.status(), is(OK));
assertThat(response.headers("X-From-Plugin"), hasItems("B", "A"));
}
use of com.hotels.styx.api.HttpHandler in project styx by ExpediaGroup.
the class StyxBackendServiceClientTest method hostHeaderIsOverwrittenWhenOverrideHostHeaderIsTrue.
@Test
public void hostHeaderIsOverwrittenWhenOverrideHostHeaderIsTrue() {
HttpInterceptor.Context requestContext = requestContext();
StyxHostHttpClient hostClient = mock(StyxHostHttpClient.class);
HttpHandler httpHandler = mock(HttpHandler.class);
Origin origin = newOriginBuilder(updatedHostName, 9090).applicationId(GENERIC_APP).build();
RemoteHost remoteHost = remoteHost(origin, httpHandler, hostClient);
LoadBalancer loadBalancer = mockLoadBalancer(Optional.of(remoteHost));
when(httpHandler.handle(any(), any())).thenReturn(Eventual.of(testResponse));
StyxBackendServiceClient styxHttpClient = new StyxBackendServiceClient.Builder(backendService.id()).originStatsFactory(mock(OriginStatsFactory.class)).originsRestrictionCookieName("someCookie").originIdHeader("origin-id").loadBalancer(loadBalancer).retryPolicy(new RetryNTimes(0)).metrics(metrics).overrideHostHeader(true).build();
styxHttpClient.sendRequest(testRequest, requestContext);
ArgumentCaptor<LiveHttpRequest> updatedRequest = ArgumentCaptor.forClass(LiveHttpRequest.class);
verify(httpHandler).handle(updatedRequest.capture(), eq(requestContext));
assertThat(updatedRequest.getValue().header(HttpHeaderNames.HOST).get(), is(updatedHostName));
}
use of com.hotels.styx.api.HttpHandler in project styx by ExpediaGroup.
the class MockOriginServer method newHandler.
private static HttpHandler newHandler(String originId, RequestHandler wireMockHandler) {
return (httpRequest, ctx) -> httpRequest.aggregate(MAX_CONTENT_LENGTH).map(fullRequest -> {
LOGGER.info("{} received: {}\n{}", new Object[] { originId, fullRequest.url(), fullRequest.body() });
return fullRequest;
}).flatMap(fullRequest -> {
Request wmRequest = new WiremockStyxRequestAdapter(fullRequest);
com.github.tomakehurst.wiremock.http.Response wmResponse = wireMockHandler.handle(wmRequest);
return Eventual.of(toStyxResponse(wmResponse).stream());
});
}
use of com.hotels.styx.api.HttpHandler in project styx by ExpediaGroup.
the class BackendServicesRouterTest method selectsUsingSingleSlashPath.
@Test
public void selectsUsingSingleSlashPath() throws Exception {
Registry.Changes<BackendService> changes = added(appA().newCopy().path("/").build(), appB().newCopy().path("/appB/hotel/details.html").build());
BackendServicesRouter router = new BackendServicesRouter(serviceClientFactory, environment, executor);
router.onChange(changes);
LiveHttpRequest request = get("/").build();
Optional<HttpHandler> route = router.route(request, context);
assertThat(proxyTo(route, request).header(ORIGIN_ID_DEFAULT), isValue(APP_A));
}
Aggregations