use of com.hotels.styx.api.HttpHandler in project styx by ExpediaGroup.
the class StyxBackendServiceClientTest method hostHeaderIsNotOverwrittenWhenOverrideHostHeaderIsFalse.
@Test
public void hostHeaderIsNotOverwrittenWhenOverrideHostHeaderIsFalse() {
HttpInterceptor.Context requestContext = requestContext();
StyxHostHttpClient hostClient = mock(StyxHostHttpClient.class);
HttpHandler httpHandler = mock(HttpHandler.class);
Origin origin = newOriginBuilder(incomingHostname, 9090).applicationId(GENERIC_APP).build();
RemoteHost remoteHost = remoteHost(origin, httpHandler, hostClient);
LoadBalancer loadBalancer = mockLoadBalancer(Optional.of(remoteHost));
when(httpHandler.handle(any(), any())).thenReturn(Eventual.of(testResponse));
StyxBackendServiceClient styxHttpClient = new StyxBackendServiceClient.Builder(backendService.id()).originStatsFactory(mock(OriginStatsFactory.class)).originsRestrictionCookieName("someCookie").originIdHeader("origin-id").loadBalancer(loadBalancer).retryPolicy(new RetryNTimes(0)).metrics(metrics).overrideHostHeader(false).build();
styxHttpClient.sendRequest(testRequest, requestContext);
verify(httpHandler).handle(testRequest, requestContext);
}
use of com.hotels.styx.api.HttpHandler in project styx by ExpediaGroup.
the class StyxBackendServiceClientTest method updatedRequestWithUpdatedHostHeaderIsPresentInResponseWhenOverrideHostHeaderIsTrue.
@Test
public void updatedRequestWithUpdatedHostHeaderIsPresentInResponseWhenOverrideHostHeaderIsTrue() {
HttpInterceptor.Context requestContext = requestContext();
StyxHostHttpClient hostClient = mock(StyxHostHttpClient.class);
HttpHandler httpHandler = mock(HttpHandler.class);
Origin origin = newOriginBuilder(updatedHostName, 9090).applicationId(GENERIC_APP).build();
RemoteHost remoteHost = remoteHost(origin, httpHandler, hostClient);
LoadBalancer loadBalancer = mockLoadBalancer(Optional.of(remoteHost));
when(httpHandler.handle(any(), any())).thenReturn(Eventual.of(testResponse));
StyxBackendServiceClient styxHttpClient = new StyxBackendServiceClient.Builder(backendService.id()).originStatsFactory(mock(OriginStatsFactory.class)).originsRestrictionCookieName("someCookie").originIdHeader("origin-id").loadBalancer(loadBalancer).retryPolicy(new RetryNTimes(0)).metrics(metrics).overrideHostHeader(true).build();
Publisher<LiveHttpResponse> responsePublisher = styxHttpClient.sendRequest(testRequest, requestContext);
StepVerifier.create(responsePublisher).expectNextMatches(it -> it.request().header(HttpHeaderNames.HOST).isPresent() && it.request().header(HttpHeaderNames.HOST).get().equals(updatedHostName)).verifyComplete();
}
use of com.hotels.styx.api.HttpHandler in project styx by ExpediaGroup.
the class StyxBackendServiceClientTest method originalRequestIsPresentInResponseWhenOverrideHostHeaderIsFalse.
@Test
public void originalRequestIsPresentInResponseWhenOverrideHostHeaderIsFalse() {
HttpInterceptor.Context requestContext = requestContext();
StyxHostHttpClient hostClient = mock(StyxHostHttpClient.class);
HttpHandler httpHandler = mock(HttpHandler.class);
Origin origin = newOriginBuilder(incomingHostname, 9090).applicationId(GENERIC_APP).build();
RemoteHost remoteHost = remoteHost(origin, httpHandler, hostClient);
LoadBalancer loadBalancer = mockLoadBalancer(Optional.of(remoteHost));
when(httpHandler.handle(any(), any())).thenReturn(Eventual.of(testResponse));
StyxBackendServiceClient styxHttpClient = new StyxBackendServiceClient.Builder(backendService.id()).originStatsFactory(mock(OriginStatsFactory.class)).originsRestrictionCookieName("someCookie").originIdHeader("origin-id").loadBalancer(loadBalancer).retryPolicy(new RetryNTimes(0)).metrics(metrics).overrideHostHeader(false).build();
Publisher<LiveHttpResponse> responsePublisher = styxHttpClient.sendRequest(testRequest, requestContext);
StepVerifier.create(responsePublisher).expectNextMatches(it -> it.request().header(HttpHeaderNames.HOST).isPresent() && it.request().header(HttpHeaderNames.HOST).get().equals(incomingHostname)).verifyComplete();
}
use of com.hotels.styx.api.HttpHandler in project styx by ExpediaGroup.
the class HttpStreamerTest method streamsRequestAndAggregatesResponses.
@Test
public void streamsRequestAndAggregatesResponses() {
HttpHandler httpHandler = (request, ctx) -> Eventual.of(LiveHttpResponse.response(OK).body(ByteStream.from("abcdef", UTF_8)).build());
HttpResponse response = Mono.from(new HttpStreamer(500, httpHandler).handle(HttpRequest.post("/").body("ABCDEF", UTF_8).build(), requestContext())).block();
assertThat(response.bodyAs(UTF_8), is("abcdef"));
}
use of com.hotels.styx.api.HttpHandler in project styx by ExpediaGroup.
the class HttpPipelineHandlerTest method mapsUnrecoverableInternalErrorsToInternalServerError500ResponseCode.
@Test
public void mapsUnrecoverableInternalErrorsToInternalServerError500ResponseCode() {
HttpHandler handler = (request, context) -> {
throw new RuntimeException("Forced exception for testing");
};
EmbeddedChannel channel = buildEmbeddedChannel(handlerWithMocks(handler));
channel.writeInbound(httpRequestAsBuf(GET, "http://foo.com/"));
DefaultHttpResponse response = (DefaultHttpResponse) channel.readOutbound();
assertThat(response.status(), is(io.netty.handler.codec.http.HttpResponseStatus.INTERNAL_SERVER_ERROR));
verify(responseEnhancer).enhance(any(LiveHttpResponse.Transformer.class), any(LiveHttpRequest.class));
verify(errorListener, only()).proxyErrorOccurred(any(LiveHttpRequest.class), any(InetSocketAddress.class), eq(INTERNAL_SERVER_ERROR), any(RuntimeException.class));
}
Aggregations