use of com.hotels.styx.api.LiveHttpResponse in project styx by ExpediaGroup.
the class NettyToStyxResponsePropagatorTest method shouldLeaveIntactQuotedCookieValues.
@Test
public void shouldLeaveIntactQuotedCookieValues() {
DefaultHttpResponse nettyResponse = new DefaultHttpResponse(HTTP_1_1, OK);
nettyResponse.headers().add("Set-Cookie", "SESSID=\"sessId\"; Domain=.foo.com; Path=/; HttpOnly");
LiveHttpResponse styxResponse = toStyxResponse(nettyResponse).build();
assertThat(styxResponse.header("Set-Cookie"), isValue("SESSID=\"sessId\"; Domain=.foo.com; Path=/; HttpOnly"));
assertThat(styxResponse.cookie("SESSID"), equalTo(Optional.of(responseCookie("SESSID", "\"sessId\"").domain(".foo.com").path("/").httpOnly(true).build())));
}
use of com.hotels.styx.api.LiveHttpResponse in project styx by ExpediaGroup.
the class NettyToStyxResponsePropagatorTest method shouldConvertNettyCookieHeaderToStyxCookies.
@Test
public void shouldConvertNettyCookieHeaderToStyxCookies() {
DefaultHttpResponse nettyResponse = new DefaultHttpResponse(HTTP_1_1, OK);
nettyResponse.headers().add("Set-Cookie", "SESSID=sessId; Domain=.foo.com; Path=/; HttpOnly");
LiveHttpResponse styxResponse = toStyxResponse(nettyResponse).build();
assertThat(styxResponse.header("Set-Cookie"), isValue("SESSID=sessId; Domain=.foo.com; Path=/; HttpOnly"));
assertThat(styxResponse.cookie("SESSID"), equalTo(Optional.of(responseCookie("SESSID", "sessId").domain(".foo.com").path("/").httpOnly(true).build())));
}
use of com.hotels.styx.api.LiveHttpResponse in project styx by ExpediaGroup.
the class StyxHttpClient method sendRequestInternal.
// Visible for testing
static Mono<LiveHttpResponse> sendRequestInternal(NettyConnectionFactory connectionFactory, LiveHttpRequest request, Builder params) {
LiveHttpRequest networkRequest = addUserAgent(params.userAgent(), request);
Origin origin = originFromRequest(networkRequest, params.https());
SslContext sslContext = getSslContext(params.https(), params.tlsSettings());
return connectionFactory.createConnection(origin, new ConnectionSettings(params.connectTimeoutMillis()), sslContext).flatMap(connection -> Mono.from(connection.write(networkRequest).doOnComplete(connection::close).doOnError(e -> connection.close()).map(response -> response.newBuilder().body(it -> it.doOnEnd(x -> connection.close()).doOnCancel(() -> connection.close())).build())));
}
use of com.hotels.styx.api.LiveHttpResponse 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.LiveHttpResponse in project styx by ExpediaGroup.
the class ModifyHeadersExamplePluginTest method addsExtraHeaders.
/**
* This tests the behaviours added in the ModifyHeadersExamplePlugin.
*/
@Test
public void addsExtraHeaders() {
// a simple way to mock the downstream system
HttpInterceptor.Chain chain = request -> {
assertThat(request.header("myRequestHeader").orElse(null), is("foo"));
return Eventual.of(response(OK).build());
};
// an example request you expect your plugin to receive
LiveHttpRequest request = get("/foo").build();
// since this is a test, we want to wait for the response
LiveHttpResponse response = Mono.from(plugin.intercept(request, chain)).block();
assertThat(response.header("myResponseHeader").orElse(null), is("bar"));
}
Aggregations