use of io.netty.handler.codec.http.HttpMethod in project riposte by Nike-Inc.
the class SimpleProxyRouterEndpoint method getDownstreamRequestFirstChunkInfo.
@Override
@NotNull
public CompletableFuture<DownstreamRequestFirstChunkInfo> getDownstreamRequestFirstChunkInfo(@NotNull RequestInfo<?> request, @NotNull Executor longRunningTaskExecutor, @NotNull ChannelHandlerContext ctx) {
HttpMethod method = request.getMethod();
if (method == null) {
CompletableFuture<DownstreamRequestFirstChunkInfo> errorResult = new CompletableFuture<>();
errorResult.completeExceptionally(new IllegalArgumentException("Received a request with null request.getMethod(). This should never happen."));
return errorResult;
}
return CompletableFuture.completedFuture(new DownstreamRequestFirstChunkInfo(downstreamDestinationHost, downstreamDestinationPort, isDownstreamCallHttps, generateSimplePassthroughRequest(request, HttpUtils.replaceUriPathVariables(request, downstreamDestinationUriPath), method, ctx), customCircuitBreaker, disableCircuitBreaker));
}
use of io.netty.handler.codec.http.HttpMethod in project riposte by Nike-Inc.
the class RequestInfoImpl method getMultipartParts.
/**
* {@inheritDoc}
*/
@Override
@Nullable
public synchronized List<InterfaceHttpData> getMultipartParts() {
if (!isMultipartRequest() || !isCompleteRequestWithAllChunks())
return null;
if (multipartData == null) {
byte[] contentBytes = getRawContentBytes();
HttpVersion httpVersion = getProtocolVersion();
HttpMethod httpMethod = getMethod();
// default them to something if null somehow slips through.
if (httpVersion == null) {
httpVersion = HttpVersion.HTTP_1_0;
}
if (httpMethod == null) {
httpMethod = HttpMethod.POST;
}
HttpRequest fullHttpRequestForMultipartDecoder = (contentBytes == null) ? new DefaultFullHttpRequest(httpVersion, httpMethod, getUri()) : new DefaultFullHttpRequest(httpVersion, httpMethod, getUri(), Unpooled.wrappedBuffer(contentBytes));
fullHttpRequestForMultipartDecoder.headers().add(getHeaders());
multipartData = new HttpPostMultipartRequestDecoder(new DefaultHttpDataFactory(false), fullHttpRequestForMultipartDecoder, getContentCharset());
}
return multipartData.getBodyHttpDatas();
}
use of io.netty.handler.codec.http.HttpMethod in project riposte by Nike-Inc.
the class AsyncHttpClientHelperTest method getRequestBuilder_with_circuit_breaker_args_sets_values_as_expected.
@DataProvider(value = { "CONNECT", "DELETE", "GET", "HEAD", "POST", "OPTIONS", "PUT", "PATCH", "TRACE", "FOO_METHOD_DOES_NOT_EXIST" }, splitBy = "\\|")
@Test
public void getRequestBuilder_with_circuit_breaker_args_sets_values_as_expected(String methodName) {
CircuitBreaker<Response> cbMock = mock(CircuitBreaker.class);
List<Pair<Optional<CircuitBreaker<Response>>, Boolean>> variations = Arrays.asList(Pair.of(Optional.empty(), true), Pair.of(Optional.empty(), false), Pair.of(Optional.of(cbMock), true), Pair.of(Optional.of(cbMock), false));
variations.forEach(variation -> {
// given
String url = "http://localhost/some/path";
HttpMethod method = HttpMethod.valueOf(methodName);
Optional<CircuitBreaker<Response>> cbOpt = variation.getLeft();
boolean disableCb = variation.getRight();
// when
RequestBuilderWrapper rbw = helperSpy.getRequestBuilder(url, method, cbOpt, disableCb);
// then
verifyRequestBuilderWrapperGeneratedAsExpected(rbw, url, methodName, cbOpt, disableCb);
});
}
use of io.netty.handler.codec.http.HttpMethod in project riposte by Nike-Inc.
the class AsyncHttpClientHelperTest method getRequestBuilder_delegates_to_helper_with_default_circuit_breaker_args.
@Test
public void getRequestBuilder_delegates_to_helper_with_default_circuit_breaker_args() {
// given
String url = UUID.randomUUID().toString();
HttpMethod method = HttpMethod.valueOf(UUID.randomUUID().toString());
RequestBuilderWrapper rbwMock = mock(RequestBuilderWrapper.class);
doReturn(rbwMock).when(helperSpy).getRequestBuilder(anyString(), any(HttpMethod.class), any(Optional.class), anyBoolean());
// when
RequestBuilderWrapper rbw = helperSpy.getRequestBuilder(url, method);
// then
verify(helperSpy).getRequestBuilder(url, method, Optional.empty(), false);
assertThat(rbw).isSameAs(rbwMock);
}
use of io.netty.handler.codec.http.HttpMethod in project riposte by Nike-Inc.
the class SignalFxEndpointMetricsHandlerTest method handleRequest_gracefully_handles_some_null_args.
@DataProvider(value = { "true | false | false", "false | true | false", "false | false | true", "true | true | true" }, splitBy = "\\|")
@Test
public void handleRequest_gracefully_handles_some_null_args(boolean endpointIsNull, boolean methodIsNull, boolean matchingPathTemplateIsNull) {
// given
int statusCode = 242;
int statusCodeXXValue = 2;
long elapsedTimeMillis = 42;
Endpoint endpoint = (endpointIsNull) ? null : endpointMock;
doReturn(endpoint).when(httpStateMock).getEndpointForExecution();
String expectedEndpointClass = (endpointIsNull) ? "NONE" : endpoint.getClass().getName();
HttpMethod method = (methodIsNull) ? null : httpMethod;
doReturn(method).when(requestInfoMock).getMethod();
String expectedMethodName = (methodIsNull) ? "NONE" : method.name();
String pathTemplate = (matchingPathTemplateIsNull) ? null : matchingPathTemplate;
doReturn(pathTemplate).when(httpStateMock).getMatchingPathTemplate();
String expectedPathTemplate = (matchingPathTemplateIsNull) ? "NONE" : pathTemplate;
// when
handler.handleRequest(requestInfoMock, responseInfoMock, httpStateMock, statusCode, statusCodeXXValue, elapsedTimeMillis);
// then
verify(metricMetadataMock).forBuilder(requestTimerBuilderMock);
verify(dimensionConfiguratorMock).setupMetricWithDimensions(timerBuilderTaggerMock, requestInfoMock, responseInfoMock, httpStateMock, statusCode, statusCodeXXValue, elapsedTimeMillis, endpoint, expectedEndpointClass, expectedMethodName, expectedPathTemplate);
verify(timerBuilderTaggerMock).createOrGet(metricRegistryMock);
verify(timerMock).update(elapsedTimeMillis, TimeUnit.MILLISECONDS);
}
Aggregations