Search in sources :

Example 51 with DefaultHttpRequest

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();
}
Also used : Attribute(io.netty.util.Attribute) Channel(io.netty.channel.Channel) HttpProcessingState(com.nike.riposte.server.http.HttpProcessingState) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) HttpTagAndSpanNamingAdapter(com.nike.wingtips.tags.HttpTagAndSpanNamingAdapter) RequestInfo(com.nike.riposte.server.http.RequestInfo) Span(com.nike.wingtips.Span) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) DefaultRiposteServerSpanNamingAndTaggingStrategy(com.nike.riposte.server.config.distributedtracing.DefaultRiposteServerSpanNamingAndTaggingStrategy) Before(org.junit.Before)

Example 52 with DefaultHttpRequest

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);
}
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 53 with DefaultHttpRequest

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();
}
Also used : HttpRequest(io.netty.handler.codec.http.HttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel)

Example 54 with DefaultHttpRequest

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();
}
Also used : DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) HttpMessage(io.netty.handler.codec.http.HttpMessage)

Example 55 with DefaultHttpRequest

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;
}
Also used : DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) HttpRequest(io.netty.handler.codec.http.HttpRequest) DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) HttpPostRequestDecoder(io.netty.handler.codec.http.multipart.HttpPostRequestDecoder)

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