use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.
the class FunctionResolverTest method resolvesZeroArgumentFunctions.
@Test
public void resolvesZeroArgumentFunctions() {
LiveHttpRequest request = get("/foo").build();
assertThat(functionResolver.resolveFunction("path", emptyList()).call(request, context), is("/foo"));
assertThat(functionResolver.resolveFunction("method", emptyList()).call(request, context), is("GET"));
}
use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.
the class CompositeHttpErrorStatusListenerTest method propagatesProxyErrorsWithRequests.
@Test
public void propagatesProxyErrorsWithRequests() {
LiveHttpRequest request = LiveHttpRequest.get("/foo").build();
IOException cause = new IOException();
InetSocketAddress clientAddress = InetSocketAddress.createUnresolved("127.0.0.1", 0);
listener.proxyErrorOccurred(request, clientAddress, INTERNAL_SERVER_ERROR, cause);
verify(delegate1).proxyErrorOccurred(request, clientAddress, INTERNAL_SERVER_ERROR, cause);
verify(delegate2).proxyErrorOccurred(request, clientAddress, INTERNAL_SERVER_ERROR, cause);
verify(delegate3).proxyErrorOccurred(request, clientAddress, INTERNAL_SERVER_ERROR, cause);
}
use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.
the class AggregateRequestBodyExamplePluginTest method contentIsModified.
@Test
public void contentIsModified() {
// Set up
Config config = new Config("MyExtraText");
String originalBody = "OriginalBody";
AggregateRequestBodyExamplePlugin plugin = new AggregateRequestBodyExamplePlugin(config);
LiveHttpRequest request = LiveHttpRequest.post("/", ByteStream.from(originalBody, UTF_8)).build();
// Our implementation of "chain.proceed()" verifies the content of the request
HttpInterceptor.Chain chain = intRequest -> {
String requestBody = Mono.from(intRequest.aggregate(100)).block().bodyAs(UTF_8);
assertThat(requestBody, is(originalBody + config.extraText()));
return Eventual.of(LiveHttpResponse.response().build());
};
// Invoke plugin and wait until it finishes execution
Mono.from(plugin.intercept(request, chain)).block();
}
use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.
the class HttpRequestMessageLoggerTest method logsClientSideResponseDetailsLongFormat.
@Test
public void logsClientSideResponseDetailsLongFormat() {
LiveHttpRequest styxRequest = get("http://www.hotels.com/foo/bar/request").build();
LiveHttpResponse styxResponse = response(OK).build();
new HttpRequestMessageLogger("com.hotels.styx.http-messages.outbound", true, httpMessageFormatter).logResponse(styxRequest, styxResponse);
assertThat(log.lastMessage(), is(loggingEvent(INFO, format("requestId=%s, response=" + FORMATTED_RESPONSE, styxRequest.id()))));
}
use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.
the class HttpRequestMessageLoggerTest method responseLogUnexpectedArguments.
private static Stream<Arguments> responseLogUnexpectedArguments() {
LiveHttpRequest normalRequest = get("http://www.hotels.com/foo/bar/request").build();
LiveHttpResponse normalResponse = response(OK).build();
return Stream.of(Arguments.of(normalRequest, null, WARN, "requestId=.*, response=null"), Arguments.of(null, normalResponse, INFO, "requestId=null, response=\\{version=HTTP/1.1, status=200 OK\\}"), Arguments.of(null, null, WARN, "requestId=null, response=null"));
}
Aggregations