use of com.hotels.styx.api.HttpInterceptor in project styx by ExpediaGroup.
the class BuiltInInterceptors method internalStyxInterceptors.
static List<HttpInterceptor> internalStyxInterceptors(StyxConfig config, HttpMessageFormatter httpMessageFormatter) {
List<HttpInterceptor> builder = new ArrayList<>();
boolean loggingEnabled = config.get("request-logging.inbound.enabled", Boolean.class).orElse(false);
boolean longFormatEnabled = config.get("request-logging.inbound.longFormat", Boolean.class).orElse(false);
if (loggingEnabled) {
builder.add(new HttpMessageLoggingInterceptor(longFormatEnabled, httpMessageFormatter));
}
builder.addAll(asList(new TcpTunnelRequestRejector(), new ConfigurationContextResolverInterceptor(EMPTY_CONFIGURATION_CONTEXT_RESOLVER), new UnexpectedRequestContentLengthRemover(), config.proxyServerConfig().via().map(ViaHeaderAppendingInterceptor::new).orElseGet(ViaHeaderAppendingInterceptor::new), new HopByHopHeadersRemovingInterceptor(), new RequestEnrichingInterceptor(config.styxHeaderConfig())));
return List.copyOf(builder);
}
use of com.hotels.styx.api.HttpInterceptor in project styx by ExpediaGroup.
the class StandardHttpPipelineTest method sendsExceptionUponExtraSubscriptionInsideInterceptor.
@ParameterizedTest
@MethodSource("multipleSubscriptionInterceptors")
public void sendsExceptionUponExtraSubscriptionInsideInterceptor(HttpInterceptor interceptor) throws Exception {
HttpHandler handler = (request, context) -> Eventual.of(response(OK).build());
List<HttpInterceptor> interceptors = singletonList(interceptor);
StandardHttpPipeline pipeline = new StandardHttpPipeline(interceptors, handler, RequestTracker.NO_OP);
Eventual<LiveHttpResponse> responseObservable = pipeline.handle(get("/").build(), requestContext());
assertThrows(IllegalStateException.class, () -> Mono.from(responseObservable).block());
}
use of com.hotels.styx.api.HttpInterceptor in project styx by ExpediaGroup.
the class StyxProxyTest method startsServerWithHttpConnector.
@Test
public void startsServerWithHttpConnector() {
HttpInterceptor echoInterceptor = (request, chain) -> textResponse("Response from http connector");
StandardHttpRouter handler = new StandardHttpRouter();
InetServer styxServer = newBuilder().setProtocolConnector(connector(0)).bossExecutor(NettyExecutor.create("Test-Server-Boss", 1)).workerExecutor(NettyExecutor.create("Test-Server-Worker", 0)).handler(new HttpInterceptorPipeline(List.of(echoInterceptor), (request, context) -> new HttpAggregator(new StandardHttpRouter()).handle(request, context), false)).build();
Service server = StyxServers.toGuavaService(styxServer);
server.startAsync().awaitRunning();
assertThat("Server should be running", server.isRunning());
HttpResponse secureResponse = get("http://localhost:" + styxServer.inetAddress().getPort());
assertThat(secureResponse.bodyAs(UTF_8), containsString("Response from http connector"));
server.stopAsync().awaitTerminated();
assertThat("Server should not be running", !server.isRunning());
}
use of com.hotels.styx.api.HttpInterceptor in project styx by ExpediaGroup.
the class StandardHttpPipelineTest method interceptorsCanPassInformationThroughContextBeforeRequest.
@Test
public void interceptorsCanPassInformationThroughContextBeforeRequest() {
HttpInterceptor addsToContext = (request, chain) -> {
chain.context().add("contextValue", "expected");
return chain.proceed(request);
};
AtomicReference<String> foundInContext = new AtomicReference<>();
HttpInterceptor takesFromContext = (request, chain) -> {
foundInContext.set(chain.context().get("contextValue", String.class));
return chain.proceed(request);
};
StandardHttpPipeline pipeline = pipeline(addsToContext, takesFromContext);
LiveHttpResponse response = sendRequestTo(pipeline);
assertThat(response.status(), is(OK));
assertThat(foundInContext.get(), is("expected"));
}
use of com.hotels.styx.api.HttpInterceptor in project styx by ExpediaGroup.
the class StandardHttpPipelineTest method contextValuesAddedBeforeRequestCanBeRetrievedAfterward.
@Test
public void contextValuesAddedBeforeRequestCanBeRetrievedAfterward() {
HttpInterceptor addsToContext = (request, chain) -> {
chain.context().add("contextValue", "expected");
return chain.proceed(request);
};
AtomicReference<String> foundInContext = new AtomicReference<>();
HttpInterceptor takesFromContext = (request, chain) -> chain.proceed(request).map(response -> {
foundInContext.set(chain.context().get("contextValue", String.class));
return response;
});
StandardHttpPipeline pipeline = pipeline(addsToContext, takesFromContext);
LiveHttpResponse response = sendRequestTo(pipeline);
assertThat(response.status(), is(OK));
assertThat(foundInContext.get(), is("expected"));
}
Aggregations