use of com.hotels.styx.api.HttpResponse in project styx by ExpediaGroup.
the class StyxServerTest method executesPluginsWhenProxying.
@Test
public void executesPluginsWhenProxying() {
Plugin responseDecorator = (request, chain) -> chain.proceed(request).map(response -> response.newBuilder().header("plugin-executed", "yes").build());
PluginFactory pluginFactory = environment -> responseDecorator;
styxServer = new StyxServer.Builder().addRoute("/", originServer1.port()).addPluginFactory("response-decorator", pluginFactory, null).start();
HttpResponse response = await(client.sendRequest(get(format("http://localhost:%d/foo", styxServer.proxyHttpPort())).build()));
assertThat(response.status(), is(OK));
assertThat(response.header("origin"), isValue("first"));
assertThat(response.header("plugin-executed"), isValue("yes"));
configureFor(originServer1.port());
WireMock.verify(getRequestedFor(urlPathEqualTo("/foo")));
}
use of com.hotels.styx.api.HttpResponse in project styx by ExpediaGroup.
the class StyxServerTest method canConfigureWithBackendService.
@Test
public void canConfigureWithBackendService() {
styxServer = new StyxServer.Builder().addRoute("/", new BackendService().addOrigin(originServer1.port())).addRoute("/o2/", new BackendService().addOrigin(originServer2.port())).start();
HttpResponse response1 = await(client.sendRequest(get(format("http://localhost:%d/foo", styxServer.proxyHttpPort())).build()));
assertThat(response1.status(), is(OK));
assertThat(response1.header("origin"), isValue("first"));
HttpResponse response2 = await(client.sendRequest(get(format("http://localhost:%d/o2/foo", styxServer.proxyHttpPort())).build()));
assertThat(response2.status(), is(OK));
assertThat(response2.header("origin"), isValue("second"));
configureFor(originServer1.port());
WireMock.verify(getRequestedFor(urlPathEqualTo("/foo")));
configureFor(originServer2.port());
WireMock.verify(getRequestedFor(urlPathEqualTo("/o2/foo")));
}
use of com.hotels.styx.api.HttpResponse in project styx by ExpediaGroup.
the class StyxServerTest method routesCorrectly.
@Test
public void routesCorrectly() {
styxServer = new StyxServer.Builder().addRoute("/", originServer1.port()).addRoute("/o2/", originServer2.port()).start();
HttpResponse response1 = await(client.sendRequest(get(format("http://localhost:%d/foo", styxServer.proxyHttpPort())).build()));
assertThat(response1.status(), is(OK));
assertThat(response1.header("origin"), isValue("first"));
HttpResponse response2 = await(client.sendRequest(get(format("http://localhost:%d/o2/foo", styxServer.proxyHttpPort())).build()));
assertThat(response2.status(), is(OK));
assertThat(response2.header("origin"), isValue("second"));
configureFor(originServer1.port());
WireMock.verify(getRequestedFor(urlPathEqualTo("/foo")));
configureFor(originServer2.port());
WireMock.verify(getRequestedFor(urlPathEqualTo("/o2/foo")));
}
use of com.hotels.styx.api.HttpResponse in project styx by ExpediaGroup.
the class StyxServerTest method proxiesToOriginViaHttps.
@Test
public void proxiesToOriginViaHttps() {
BackendService backendService = new BackendService().ssl().addOrigin(secureOriginServer.httpsPort());
styxServer = new StyxServer.Builder().addRoute("/", backendService).start();
StyxHttpClient tlsClient = new StyxHttpClient.Builder().tlsSettings(new TlsSettings.Builder().build()).build();
HttpResponse response = await(tlsClient.sendRequest(get(format("https://localhost:%d/", styxServer.proxyHttpsPort())).build()));
assertThat(response.status(), is(OK));
configureFor(secureOriginServer.port());
WireMock.verify(getRequestedFor(urlPathEqualTo("/")));
}
use of com.hotels.styx.api.HttpResponse in project styx by ExpediaGroup.
the class StaticFileOnRealServerIT method shouldWorkInRealServer.
@Test
public void shouldWorkInRealServer() throws Exception {
writeFile("index.html", "Hello World");
writeFile("foo.js", "some js");
mkdir("some/dir");
writeFile("some/dir/content1.txt", "some txt");
HttpRequest request = new HttpRequest.Builder(GET, "/index.html").header("Host", serverEndpoint).build();
HttpResponse response = await(client.sendRequest(request));
assertThat(response.bodyAs(UTF_8), is("Hello World"));
}
Aggregations