use of io.netty.handler.codec.http.DefaultHttpRequest in project riposte by Nike-Inc.
the class DTraceStartHandlerTest method beforeMethod.
@Before
public void beforeMethod() {
channelMock = mock(Channel.class);
ctxMock = mock(ChannelHandlerContext.class);
stateAttributeMock = mock(Attribute.class);
state = new HttpProcessingState();
httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/some/uri");
requestInfoMock = mock(RequestInfo.class);
doReturn(channelMock).when(ctxMock).channel();
doReturn(stateAttributeMock).when(channelMock).attr(ChannelAttributes.HTTP_PROCESSING_STATE_ATTRIBUTE_KEY);
doReturn(state).when(stateAttributeMock).get();
state.setRequestInfo(requestInfoMock);
initialSpanNameFromStrategy = new AtomicReference<>("span-name-from-strategy-" + UUID.randomUUID().toString());
strategyInitialSpanNameMethodCalled = new AtomicBoolean(false);
strategyRequestTaggingMethodCalled = new AtomicBoolean(false);
strategyResponseTaggingAndFinalSpanNameMethodCalled = new AtomicBoolean(false);
strategyInitialSpanNameArgs = new AtomicReference<>(null);
strategyRequestTaggingArgs = new AtomicReference<>(null);
strategyResponseTaggingArgs = new AtomicReference<>(null);
tagAndNamingStrategy = new ArgCapturingHttpTagAndSpanNamingStrategy<>(initialSpanNameFromStrategy, strategyInitialSpanNameMethodCalled, strategyRequestTaggingMethodCalled, strategyResponseTaggingAndFinalSpanNameMethodCalled, strategyInitialSpanNameArgs, strategyRequestTaggingArgs, strategyResponseTaggingArgs);
tagAndNamingAdapterMock = mock(HttpTagAndSpanNamingAdapter.class);
distributedTracingConfig = new DistributedTracingConfigImpl<>(new DefaultRiposteServerSpanNamingAndTaggingStrategy(tagAndNamingStrategy, tagAndNamingAdapterMock) {
@Override
public boolean shouldAddWireReceiveStartAnnotation() {
return shouldAddWireReceiveStartAnnotation;
}
@Override
public boolean shouldAddWireReceiveFinishAnnotation() {
return shouldAddWireReceiveFinishAnnotation;
}
}, DefaultRiposteProxyRouterSpanNamingAndTaggingStrategy.getDefaultInstance(), Span.class);
handler = new DTraceStartHandler(userIdHeaderKeys, distributedTracingConfig);
resetTracingAndMdc();
}
use of io.netty.handler.codec.http.DefaultHttpRequest in project riposte by Nike-Inc.
the class ExceptionHandlingHandlerTest method getRequestInfo_uses_dummy_instance_if_an_exception_occurs_while_creating_RequestInfo_from_HttpRequest_msg.
@Test
public void getRequestInfo_uses_dummy_instance_if_an_exception_occurs_while_creating_RequestInfo_from_HttpRequest_msg() {
// given
assertThat(state.getRequestInfo(), nullValue());
RiposteHandlerInternalUtil explodingHandlerUtilMock = mock(RiposteHandlerInternalUtil.class);
doThrow(new RuntimeException("intentional exception")).when(explodingHandlerUtilMock).createRequestInfoFromNettyHttpRequestAndHandleStateSetupIfNecessary(any(), any());
Whitebox.setInternalState(handler, "handlerUtils", explodingHandlerUtilMock);
HttpRequest httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/some/uri");
// when
RequestInfo<?> result = handler.getRequestInfo(state, httpRequest);
// then
assertThat(result.getUri(), is(RequestInfo.NONE_OR_UNKNOWN_TAG));
verify(explodingHandlerUtilMock).createRequestInfoFromNettyHttpRequestAndHandleStateSetupIfNecessary(httpRequest, state);
}
use of io.netty.handler.codec.http.DefaultHttpRequest in project reactor-netty by reactor.
the class HttpServerTests method doTestIsFormUrlencoded.
@SuppressWarnings("FutureReturnValueIgnored")
private void doTestIsFormUrlencoded(String headerValue, boolean expectation) {
EmbeddedChannel channel = new EmbeddedChannel();
HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/");
request.headers().set(HttpHeaderNames.CONTENT_TYPE, headerValue);
HttpServerOperations ops = new HttpServerOperations(Connection.from(channel), ConnectionObserver.emptyListener(), request, null, null, ServerCookieDecoder.STRICT, ServerCookieEncoder.STRICT, DEFAULT_FORM_DECODER_SPEC, null, false);
assertThat(ops.isFormUrlencoded()).isEqualTo(expectation);
// "FutureReturnValueIgnored" is suppressed deliberately
channel.close();
}
use of io.netty.handler.codec.http.DefaultHttpRequest in project reactor-netty by reactor.
the class HttpServerTests method doTestStatus.
@SuppressWarnings("FutureReturnValueIgnored")
private void doTestStatus(HttpResponseStatus status) {
EmbeddedChannel channel = new EmbeddedChannel();
HttpServerOperations ops = new HttpServerOperations(Connection.from(channel), ConnectionObserver.emptyListener(), new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/"), null, null, ServerCookieDecoder.STRICT, ServerCookieEncoder.STRICT, DEFAULT_FORM_DECODER_SPEC, null, false);
ops.status(status);
HttpMessage response = ops.newFullBodyMessage(Unpooled.EMPTY_BUFFER);
assertThat(((FullHttpResponse) response).status().reasonPhrase()).isEqualTo(status.reasonPhrase());
// "FutureReturnValueIgnored" is suppressed deliberately
channel.close();
}
use of io.netty.handler.codec.http.DefaultHttpRequest in project vert.x by eclipse.
the class Http2ServerRequestImpl method setExpectMultipart.
@Override
public HttpServerRequest setExpectMultipart(boolean expect) {
synchronized (conn) {
checkEnded();
if (expect) {
if (postRequestDecoder == null) {
CharSequence contentType = headers.get(HttpHeaderNames.CONTENT_TYPE);
if (contentType != null) {
io.netty.handler.codec.http.HttpMethod method = io.netty.handler.codec.http.HttpMethod.valueOf(headers.method().toString());
String lowerCaseContentType = contentType.toString().toLowerCase();
boolean isURLEncoded = lowerCaseContentType.startsWith(HttpHeaderValues.APPLICATION_X_WWW_FORM_URLENCODED.toString());
if ((lowerCaseContentType.startsWith(HttpHeaderValues.MULTIPART_FORM_DATA.toString()) || isURLEncoded) && (method == io.netty.handler.codec.http.HttpMethod.POST || method == io.netty.handler.codec.http.HttpMethod.PUT || method == io.netty.handler.codec.http.HttpMethod.PATCH || method == io.netty.handler.codec.http.HttpMethod.DELETE)) {
HttpRequest req = new DefaultHttpRequest(io.netty.handler.codec.http.HttpVersion.HTTP_1_1, method, headers.path().toString());
req.headers().add(HttpHeaderNames.CONTENT_TYPE, contentType);
postRequestDecoder = new HttpPostRequestDecoder(new NettyFileUploadDataFactory(vertx, this, () -> uploadHandler), req);
}
}
}
} else {
postRequestDecoder = null;
}
}
return this;
}
Aggregations