use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.
the class NettyToStyxRequestDecoderTest method overridesTheHostHeaderWithTheHostAndPortInTheAbsoluteURI.
@Test
public void overridesTheHostHeaderWithTheHostAndPortInTheAbsoluteURI() {
HttpRequest request = newHttpRequest(URI.create("http://example.net/foo").toString());
request.headers().set(HOST, "www.example.com:8000");
LiveHttpRequest styxRequest = decode(request);
assertThat(styxRequest.headers().get(HOST).get(), is("example.net"));
}
use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.
the class NettyToStyxRequestDecoderTest method canHandleNettyCookies.
@Test
public void canHandleNettyCookies() {
HttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, GET, "http://foo.com/");
request.headers().set(HOST, "http://foo.com/");
request.headers().set("Cookie", "ABC01=\"1\"; ABC02=1; guid=xxxxx-xxx-xxx-xxx-xxxxxxx");
NettyToStyxRequestDecoder decoder = new NettyToStyxRequestDecoder.Builder().uniqueIdSupplier(uniqueIdSupplier).flowControlEnabled(true).build();
LiveHttpRequest styxRequest = decoder.makeAStyxRequestFrom(request, Observable.<ByteBuf>empty()).build();
LiveHttpRequest expected = new LiveHttpRequest.Builder(HttpMethod.GET, "http://foo.com/").cookies(requestCookie("ABC01", "\"1\""), requestCookie("ABC02", "1"), requestCookie("guid", "xxxxx-xxx-xxx-xxx-xxxxxxx")).build();
assertThat(new HashSet<>(styxRequest.cookies()), is(new HashSet<>(expected.cookies())));
}
use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.
the class HttpPipelineHandlerTest method cancelsOngoingRequestWhenSpuriousRequestArrivesInWaitingForResponseState.
@Test
public void cancelsOngoingRequestWhenSpuriousRequestArrivesInWaitingForResponseState() throws Exception {
// - writes EMPTY_LAST_CONTENT and closes the channel
// - logs an error message
// - cancels the ongoing request on the HTTP pipeline
LiveHttpRequest spurious = get("/bar").build();
setupHandlerTo(WAITING_FOR_RESPONSE);
handler.channelRead0(ctx, spurious);
verify(statsCollector).onTerminate(request.id());
assertThat(handler.state(), is(TERMINATED));
assertThat(logger.lastMessage(), is(loggingEvent(WARN, "message='Spurious request received while handling another request'.*")));
assertThat(responseUnsubscribed.get(), is(true));
}
use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.
the class AntlrConditionTest method notExpressionNegatesTheExpressionResult.
@Test
public void notExpressionNegatesTheExpressionResult() {
Condition condition = condition("NOT header('Host')");
LiveHttpRequest request1 = newRequest().header(HOST, "bbc.co.uk").build();
assertThat(condition.evaluate(request1, context), is(false));
LiveHttpRequest request2 = newRequest().header(CONTENT_LENGTH, 7).build();
assertThat(condition.evaluate(request2, context), is(true));
}
use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.
the class AntlrConditionTest method notExpressionHasHigherPrecedenceThanAndExpression.
@Test
public void notExpressionHasHigherPrecedenceThanAndExpression() {
Condition condition = condition("header('Host') " + "AND NOT header('App-Name') =~ 'app[0-9]' OR header('App-Name') =~ 'shop[0-9]'");
LiveHttpRequest request1 = newRequest().header(HOST, "bbc.co.uk").header("App-Name", "landing1").build();
assertThat(condition.evaluate(request1, context), is(true));
LiveHttpRequest request2 = newRequest().header(HOST, "bbc.co.uk").header("App-Name", "app2").build();
assertThat(condition.evaluate(request2, context), is(false));
LiveHttpRequest request3 = newRequest().header(HOST, "bbc.co.uk").header("App-Name", "shop1").build();
assertThat(condition.evaluate(request3, context), is(true));
}
Aggregations