Search in sources :

Example 41 with LiveHttpRequest

use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.

the class HttpMessageLoggingInterceptorTest method logsRequestsAndResponses.

@Test
public void logsRequestsAndResponses() {
    LiveHttpRequest request = get("/").version(HttpVersion.HTTP_1_1).header("ReqHeader", "ReqHeaderValue").cookies(requestCookie("ReqCookie", "ReqCookieValue")).build();
    consume(interceptor.intercept(request, chain(response(OK).header("RespHeader", "RespHeaderValue").cookies(responseCookie("RespCookie", "RespCookieValue").build()))));
    assertThat(responseLogSupport.log(), contains(loggingEvent(INFO, "requestId=" + request.id() + ", secure=true, origin=null, request=" + FORMATTED_REQUEST), loggingEvent(INFO, "requestId=" + request.id() + ", secure=true, response=" + FORMATTED_RESPONSE)));
}
Also used : LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) Test(org.junit.jupiter.api.Test)

Example 42 with LiveHttpRequest

use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.

the class HttpMessageLoggingInterceptorTest method logsRequestsAndResponsesShort.

@Test
public void logsRequestsAndResponsesShort() {
    interceptor = new HttpMessageLoggingInterceptor(false, httpMessageFormatter);
    LiveHttpRequest request = get("/").header("ReqHeader", "ReqHeaderValue").cookies(requestCookie("ReqCookie", "ReqCookieValue")).build();
    consume(interceptor.intercept(request, chain(response(OK).header("RespHeader", "RespHeaderValue").cookies(responseCookie("RespCookie", "RespCookieValue").build()))));
    String requestPattern = "request=\\{version=HTTP/1.1, method=GET, uri=/, id=" + request.id() + "\\}";
    String responsePattern = "response=\\{version=HTTP/1.1, status=200 OK\\}";
    assertThat(responseLogSupport.log(), contains(loggingEvent(INFO, "requestId=" + request.id() + ", secure=true, origin=null, " + requestPattern), loggingEvent(INFO, "requestId=" + request.id() + ", secure=true, " + responsePattern)));
}
Also used : LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) Test(org.junit.jupiter.api.Test)

Example 43 with LiveHttpRequest

use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.

the class UnexpectedRequestContentLengthRemoverTest method removesContentLengthIfBothContentLengthAndChunkedHeaderExists.

@Test
public void removesContentLengthIfBothContentLengthAndChunkedHeaderExists() throws Exception {
    LiveHttpRequest request = get("/foo").header(CONTENT_LENGTH, "50").header(TRANSFER_ENCODING, CHUNKED).build();
    LiveHttpRequest interceptedRequest = interceptRequest(request);
    assertThat(interceptedRequest.contentLength(), isAbsent());
    assertThat(interceptedRequest.chunked(), is(true));
}
Also used : LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) Test(org.junit.jupiter.api.Test)

Example 44 with LiveHttpRequest

use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.

the class ViaHeaderAppendingInterceptorTest method appendsViaHeaderValueAtEndOfTheViaList.

@Test
public void appendsViaHeaderValueAtEndOfTheViaList() throws Exception {
    LiveHttpRequest request = post("/foo").header(VIA, "1.0 ricky, 1.1 mertz, 1.0 lucy").build();
    LiveHttpRequest interceptedRequest = interceptRequest(interceptor, request);
    assertThat(interceptedRequest.headers().get(VIA), isValue("1.0 ricky, 1.1 mertz, 1.0 lucy, 1.1 styx"));
}
Also used : LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) Test(org.junit.jupiter.api.Test)

Example 45 with LiveHttpRequest

use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.

the class ViaHeaderAppendingInterceptorTest method appendsHttp10RequestVersionInRequestViaHeader.

@Test
public void appendsHttp10RequestVersionInRequestViaHeader() throws Exception {
    LiveHttpRequest request = post("/foo").version(HTTP_1_0).header(VIA, "").build();
    LiveHttpRequest interceptedRequest = interceptRequest(interceptor, request);
    assertThat(interceptedRequest.headers().get(VIA), isValue("1.0 styx"));
}
Also used : LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) Test(org.junit.jupiter.api.Test)

Aggregations

LiveHttpRequest (com.hotels.styx.api.LiveHttpRequest)82 Test (org.junit.jupiter.api.Test)76 Condition (com.hotels.styx.server.routing.Condition)19 LiveHttpResponse (com.hotels.styx.api.LiveHttpResponse)14 HttpHandler (com.hotels.styx.api.HttpHandler)10 MicrometerRegistry (com.hotels.styx.api.MicrometerRegistry)9 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)9 MeterRegistry (com.hotels.styx.api.MeterRegistry)8 BackendService (com.hotels.styx.api.extension.service.BackendService)7 Registry (com.hotels.styx.api.extension.service.spi.Registry)7 Eventual (com.hotels.styx.api.Eventual)6 HttpInterceptor (com.hotels.styx.api.HttpInterceptor)6 HttpResponse (com.hotels.styx.api.HttpResponse)5 Origin.newOriginBuilder (com.hotels.styx.api.extension.Origin.newOriginBuilder)5 DefaultHttpRequest (io.netty.handler.codec.http.DefaultHttpRequest)5 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 Mono (reactor.core.publisher.Mono)5 HttpRequestMessageLogger (com.hotels.styx.common.logging.HttpRequestMessageLogger)4 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)4