use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.
the class ViaHeaderAppendingInterceptorTest method addsCustomViaHeader.
@Test
public void addsCustomViaHeader() throws Exception {
final String customVia = "MyAwesomeProxy";
final LiveHttpRequest interceptedRequest = interceptRequest(new ViaHeaderAppendingInterceptor(customVia), post("/foo").header(HOST, "www.example.com:8000").build());
assertThat(interceptedRequest.headers().get(VIA), isValue("1.1 " + customVia));
}
use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.
the class StyxBackendServiceClientTest method hostHeaderIsOverwrittenWhenOverrideHostHeaderIsTrue.
@Test
public void hostHeaderIsOverwrittenWhenOverrideHostHeaderIsTrue() {
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();
styxHttpClient.sendRequest(testRequest, requestContext);
ArgumentCaptor<LiveHttpRequest> updatedRequest = ArgumentCaptor.forClass(LiveHttpRequest.class);
verify(httpHandler).handle(updatedRequest.capture(), eq(requestContext));
assertThat(updatedRequest.getValue().header(HttpHeaderNames.HOST).get(), is(updatedHostName));
}
use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.
the class HttpRequestMessageLoggerTest method logsClientSideRequestLongFormat.
@Test
public void logsClientSideRequestLongFormat() {
LiveHttpRequest styxRequest = get("http://www.hotels.com/foo/bar/request").build();
new HttpRequestMessageLogger("com.hotels.styx.http-messages.outbound", true, httpMessageFormatter).logRequest(styxRequest, origin, true);
assertThat(log.lastMessage(), is(loggingEvent(INFO, format("requestId=%s, secure=true, origin=%s, request=" + FORMATTED_REQUEST, styxRequest.id(), origin))));
}
use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.
the class HttpRequestOperationTest method shouldTransformUrlQueryParametersToNettyRequest.
@Test
public void shouldTransformUrlQueryParametersToNettyRequest() {
LiveHttpRequest request = new LiveHttpRequest.Builder().method(GET).header("X-Forwarded-Proto", "https").uri("https://www.example.com/foo?some=value&blah=blah").build();
LiveHttpRequest.Transformer builder = request.newBuilder();
LiveHttpRequest newRequest = builder.url(request.url().newBuilder().addQueryParam("format", "json").build()).build();
DefaultHttpRequest nettyRequest = HttpRequestOperation.toNettyRequest(newRequest);
assertThat(nettyRequest.method(), is(io.netty.handler.codec.http.HttpMethod.GET));
assertThat(nettyRequest.uri(), is("https://www.example.com/foo?some=value&blah=blah&format=json"));
assertThat(nettyRequest.headers().get("X-Forwarded-Proto"), is("https"));
}
use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.
the class HttpRequestMessageLoggerTest method logsClientSideRequestShortFormat.
@Test
public void logsClientSideRequestShortFormat() {
LiveHttpRequest styxRequest = get("http://www.hotels.com/foo/bar/request").build();
new HttpRequestMessageLogger("com.hotels.styx.http-messages.outbound", false, httpMessageFormatter).logRequest(styxRequest, origin, true);
assertThat(log.lastMessage(), is(loggingEvent(INFO, format("requestId=%s, secure=true, origin=%s, request=\\{version=HTTP/1.1, method=GET, uri=%s, id=%s}", styxRequest.id(), origin, styxRequest.url(), styxRequest.id()))));
}
Aggregations