Search in sources :

Example 86 with DefaultHttpRequest

use of io.netty.handler.codec.http.DefaultHttpRequest in project riposte by Nike-Inc.

the class ExceptionHandlingHandlerTest method getRequestInfo_creates_new_RequestInfo_based_on_msg_if_state_requestInfo_is_null_and_msg_is_a_HttpRequest.

@Test
public void getRequestInfo_creates_new_RequestInfo_based_on_msg_if_state_requestInfo_is_null_and_msg_is_a_HttpRequest() {
    // given
    assertThat(state.getRequestInfo(), nullValue());
    String expectedUri = "/some/uri/" + UUID.randomUUID().toString();
    HttpRequest httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, expectedUri);
    // when
    RequestInfo<?> result = handler.getRequestInfo(state, httpRequest);
    // then
    assertThat(result.getUri(), is(expectedUri));
}
Also used : DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) HttpRequest(io.netty.handler.codec.http.HttpRequest) DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) Test(org.junit.Test)

Example 87 with DefaultHttpRequest

use of io.netty.handler.codec.http.DefaultHttpRequest in project riposte by Nike-Inc.

the class RiposteHandlerInternalUtilTest method determineOverallRequestSpanName_works_as_expected.

@UseDataProvider("determineOverallRequestSpanNameScenarioDataProvider")
@Test
public void determineOverallRequestSpanName_works_as_expected(DetermineSpanNameScenario scenario) {
    // given
    ServerSpanNamingAndTaggingStrategy<Span> namingStrategy = new DummyServerSpanNamingAndTaggingStrategy(scenario.strategySpanName);
    doReturn(scenario.fallbackSpanName).when(implSpy).determineFallbackOverallRequestSpanName(any());
    RequestInfo<?> requestInfoMock = mock(RequestInfo.class);
    if (scenario.riposteRequestInfoIsNull) {
        requestInfoMock = null;
    }
    HttpRequest httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/some/uri");
    String expectedResult = (scenario.expectStrategyResult) ? scenario.strategySpanName : scenario.fallbackSpanName;
    // when
    String result = implSpy.determineOverallRequestSpanName(httpRequest, requestInfoMock, namingStrategy);
    // then
    Assertions.assertThat(result).isEqualTo(expectedResult);
    if (scenario.expectStrategyResult) {
        verify(implSpy, never()).determineFallbackOverallRequestSpanName(any());
    } else {
        verify(implSpy).determineFallbackOverallRequestSpanName(httpRequest);
    }
}
Also used : DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) HttpRequest(io.netty.handler.codec.http.HttpRequest) DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) Span(com.nike.wingtips.Span) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 88 with DefaultHttpRequest

use of io.netty.handler.codec.http.DefaultHttpRequest in project riposte by Nike-Inc.

the class RiposteHandlerInternalUtilTest method beforeMethod.

@Before
public void beforeMethod() {
    implSpy = spy(new RiposteHandlerInternalUtil());
    stateSpy = spy(new HttpProcessingState());
    nettyRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PATCH, "/some/uri");
    resetTracingAndMdc();
}
Also used : DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) HttpProcessingState(com.nike.riposte.server.http.HttpProcessingState) Before(org.junit.Before)

Example 89 with DefaultHttpRequest

use of io.netty.handler.codec.http.DefaultHttpRequest in project riposte by Nike-Inc.

the class ProxyRouterEndpoint method generateSimplePassthroughRequest.

/**
 * Helper method that generates a {@link HttpRequest} for the downstream call's first chunk that uses the given
 * downstreamPath and downstreamMethod, and the query string and headers from the incomingRequest will be added and
 * passed through without modification.
 */
@SuppressWarnings("UnusedParameters")
@NotNull
protected HttpRequest generateSimplePassthroughRequest(@NotNull RequestInfo<?> incomingRequest, @NotNull String downstreamPath, @NotNull HttpMethod downstreamMethod, @NotNull ChannelHandlerContext ctx) {
    String queryString = extractQueryString(incomingRequest.getUri());
    String downstreamUri = downstreamPath;
    // TODO: Add logic to support when downstreamPath already has a query string on it. The two query strings should be combined
    if (queryString != null)
        downstreamUri += queryString;
    HttpRequest downstreamRequestInfo = new DefaultHttpRequest(HttpVersion.HTTP_1_1, downstreamMethod, downstreamUri);
    downstreamRequestInfo.headers().set(incomingRequest.getHeaders());
    return downstreamRequestInfo;
}
Also used : HttpRequest(io.netty.handler.codec.http.HttpRequest) DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) NotNull(org.jetbrains.annotations.NotNull)

Example 90 with DefaultHttpRequest

use of io.netty.handler.codec.http.DefaultHttpRequest in project riposte by Nike-Inc.

the class StreamingAsyncHttpClientTest method streamDownstreamCall_setsHostHeaderCorrectly.

@DataProvider(value = { "80   | false | localhost | localhost", "80   | true  | localhost | localhost:80", "8080 | false | localhost | localhost:8080", "443  | true  | localhost | localhost", "443  | false | localhost | localhost:443", "8080 | true  | localhost | localhost:8080" }, splitBy = "\\|")
@Test
public void streamDownstreamCall_setsHostHeaderCorrectly(int downstreamPort, boolean isSecure, String downstreamHost, String expectedHostHeader) {
    // given
    DefaultHttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "");
    ChannelHandlerContext ctx = mockChannelHandlerContext();
    StreamingCallback streamingCallback = mock(StreamingCallback.class);
    ProxyRouterProcessingState proxyState = ChannelAttributes.getProxyRouterProcessingStateForChannel(ctx).get();
    RequestInfo<?> requestInfoMock = mock(RequestInfo.class);
    // when
    new StreamingAsyncHttpClient(200, 200, true, mock(DistributedTracingConfig.class)).streamDownstreamCall(downstreamHost, downstreamPort, request, isSecure, false, streamingCallback, 200, true, true, proxyState, requestInfoMock, ctx);
    // then
    assertThat(request.headers().get(HOST)).isEqualTo(expectedHostHeader);
}
Also used : StreamingCallback(com.nike.riposte.client.asynchttp.netty.StreamingAsyncHttpClient.StreamingCallback) DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ProxyRouterProcessingState(com.nike.riposte.server.http.ProxyRouterProcessingState) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Aggregations

DefaultHttpRequest (io.netty.handler.codec.http.DefaultHttpRequest)115 HttpRequest (io.netty.handler.codec.http.HttpRequest)81 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)53 Test (org.junit.Test)51 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)44 HttpMethod (io.netty.handler.codec.http.HttpMethod)23 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)20 DefaultLastHttpContent (io.netty.handler.codec.http.DefaultLastHttpContent)18 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)16 HttpContent (io.netty.handler.codec.http.HttpContent)13 HttpObject (io.netty.handler.codec.http.HttpObject)13 DefaultHttpContent (io.netty.handler.codec.http.DefaultHttpContent)12 ByteBuf (io.netty.buffer.ByteBuf)11 HttpTrade (org.jocean.http.server.HttpServerBuilder.HttpTrade)11 Test (org.junit.jupiter.api.Test)10 Channel (io.netty.channel.Channel)9 ArrayList (java.util.ArrayList)9 Nettys4Test (org.jocean.http.util.Nettys4Test)9 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)8 DisposableWrapper (org.jocean.idiom.DisposableWrapper)6