use of com.hotels.styx.api.HttpInterceptor in project styx by ExpediaGroup.
the class StandardHttpPipelineTest method interceptorsCanPassInformationThroughContextAfterRequest.
@Test
public void interceptorsCanPassInformationThroughContextAfterRequest() {
HttpInterceptor addsToContext = (request, chain) -> chain.proceed(request).map(response -> {
chain.context().add("contextValue", "expected");
return response;
});
AtomicReference<String> foundInContext = new AtomicReference<>();
HttpInterceptor takesFromContext = (request, chain) -> chain.proceed(request).map(response -> {
foundInContext.set(chain.context().get("contextValue", String.class));
return response;
});
// add + take happens on the way back, so order must be reserved
StandardHttpPipeline pipeline = pipeline(takesFromContext, addsToContext);
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 interceptorReceivesNewContext.
@Test
public void interceptorReceivesNewContext() {
HttpInterceptor expectNewContext = (request, chain) -> {
Object seen = chain.context().get("seen", Object.class);
assertThat("Old context reused" + seen, seen, is(nullValue()));
chain.context().add("seen", true);
return chain.proceed(request);
};
StandardHttpPipeline pipeline = pipeline(expectNewContext);
assertThat(sendRequestTo(pipeline).status(), is(OK));
// make the same request again to ensure a new context is used
assertThat(sendRequestTo(pipeline).status(), is(OK));
}
Aggregations