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));
}
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);
}
}
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();
}
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;
}
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);
}
Aggregations