use of com.hotels.styx.api.HttpResponse in project styx by ExpediaGroup.
the class StyxServerTest method exposesAdminEndpoints.
@Test
public void exposesAdminEndpoints() {
setUpStyxAndPluginWithAdminPages(Map.of("adminPage1", (request, ctx) -> Eventual.of(LiveHttpResponse.response().header("AdminPage1", "yes").build()), "adminPage2", (request, ctx) -> Eventual.of(LiveHttpResponse.response().header("AdminPage2", "yes").build())));
HttpResponse response = doAdminRequest("/admin/plugins/plugin-with-admin-pages/adminPage1");
assertThat(response.status(), is(OK));
assertThat(response.header("AdminPage1"), isValue("yes"));
response = doAdminRequest("/admin/plugins/plugin-with-admin-pages/adminPage2");
assertThat(response.status(), is(OK));
assertThat(response.header("AdminPage2"), isValue("yes"));
}
use of com.hotels.styx.api.HttpResponse in project styx by ExpediaGroup.
the class EarlyReturnExamplePluginTest method returnsEarlyWhenHeaderIsPresent.
@Test
public void returnsEarlyWhenHeaderIsPresent() {
EarlyReturnExamplePlugin plugin = new EarlyReturnExamplePlugin();
LiveHttpRequest request = LiveHttpRequest.get("/").header("X-Respond", "foo").build();
HttpInterceptor.Chain chain = request1 -> Eventual.of(LiveHttpResponse.response().build());
Eventual<LiveHttpResponse> eventualLive = plugin.intercept(request, chain);
Eventual<HttpResponse> eventual = eventualLive.flatMap(response -> response.aggregate(100));
HttpResponse response = Mono.from(eventual).block();
assertThat(response.bodyAs(UTF_8), is("Responding from plugin"));
}
use of com.hotels.styx.api.HttpResponse in project styx by ExpediaGroup.
the class ModifyContentByAggregationExamplePluginTest method modifiesContent.
@Test
public void modifiesContent() {
// Set up
Config config = new Config("MyExtraText");
ModifyContentByAggregationExamplePlugin plugin = new ModifyContentByAggregationExamplePlugin(config);
LiveHttpRequest request = get("/").build();
HttpInterceptor.Chain chain = anyRequest -> Eventual.of(response().body("OriginalBody", UTF_8).build().stream());
// Execution
HttpResponse response = Mono.from(plugin.intercept(request, chain).flatMap(liveResponse -> liveResponse.aggregate(100))).block();
// Assertion
assertThat(response.bodyAs(UTF_8), is("OriginalBodyMyExtraText"));
}
use of com.hotels.styx.api.HttpResponse in project styx by ExpediaGroup.
the class ReplaceLiveContentExamplePluginTest method replacesLiveContent.
@Test
public void replacesLiveContent() {
// Set up
ReplaceLiveContentExampleConfig config = new ReplaceLiveContentExampleConfig("myNewContent");
ReplaceLiveContentExamplePlugin plugin = new ReplaceLiveContentExamplePlugin(config);
LiveHttpRequest request = get("/").build();
HttpInterceptor.Chain chain = request1 -> Eventual.of(LiveHttpResponse.response().build());
// Execution
HttpResponse response = Mono.from(plugin.intercept(request, chain).flatMap(liveResponse -> liveResponse.aggregate(100))).block();
// Assertion
assertThat(response.bodyAs(UTF_8), is("myNewContent"));
}
use of com.hotels.styx.api.HttpResponse in project styx by ExpediaGroup.
the class ProtocolMetricsTest method recordsServerSideHttps.
@Test
public void recordsServerSideHttps() {
styxServer = new StyxServer.Builder().addRoute("/", origin.port()).start();
HttpResponse response = doHttpsGet("/");
assertThat(response.status(), is(OK));
assertThat(styxServer.metrics().meter("styx.server.http.requests").getCount(), is(0L));
assertThat(styxServer.metrics().meter("styx.server.https.requests").getCount(), is(1L));
assertThat(styxServer.metrics().meter("styx.server.http.responses.200").getCount(), is(0L));
assertThat(styxServer.metrics().meter("styx.server.https.responses.200").getCount(), is(1L));
}
Aggregations