Search in sources :

Example 1 with HttpMessage

use of io.netty.handler.codec.http.HttpMessage in project reactor-netty by reactor.

the class HttpOperations method then.

@Override
public Mono<Void> then() {
    if (hasSentHeaders()) {
        return Mono.empty();
    }
    return FutureMono.deferFuture(() -> {
        if (markSentHeaders()) {
            HttpMessage msg;
            if (HttpUtil.isContentLengthSet(outboundHttpMessage())) {
                outboundHttpMessage().headers().remove(HttpHeaderNames.TRANSFER_ENCODING);
                if (HttpUtil.getContentLength(outboundHttpMessage(), 0) == 0) {
                    msg = newFullEmptyBodyMessage();
                } else {
                    msg = outboundHttpMessage();
                }
            } else {
                msg = outboundHttpMessage();
            }
            preSendHeadersAndStatus();
            return channel().writeAndFlush(msg);
        } else {
            return channel().newSucceededFuture();
        }
    });
}
Also used : HttpMessage(io.netty.handler.codec.http.HttpMessage) FullHttpMessage(io.netty.handler.codec.http.FullHttpMessage)

Example 2 with HttpMessage

use of io.netty.handler.codec.http.HttpMessage in project pinpoint by naver.

the class HttpEncoderInterceptor method doInBeforeTrace.

protected void doInBeforeTrace(SpanEventRecorder recorder, Trace trace, Object target, Object[] args) {
    // generate next trace id.
    final TraceId nextId = trace.getTraceId().getNextTraceId();
    recorder.recordNextSpanId(nextId.getSpanId());
    recorder.recordServiceType(NettyConstants.SERVICE_TYPE_CODEC_HTTP);
    final ChannelHandlerContext channelHandlerContext = (ChannelHandlerContext) args[0];
    final HttpMessage httpMessage = (HttpMessage) args[1];
    final String host = getHost(channelHandlerContext);
    this.requestTraceWriter.write(httpMessage, nextId, host);
}
Also used : TraceId(com.navercorp.pinpoint.bootstrap.context.TraceId) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) HttpMessage(io.netty.handler.codec.http.HttpMessage)

Example 3 with HttpMessage

use of io.netty.handler.codec.http.HttpMessage in project pinpoint by naver.

the class HttpEncoderInterceptor method doInAfterTrace.

protected void doInAfterTrace(SpanEventRecorder recorder, Object target, Object[] args, Object result, Throwable throwable) {
    recorder.recordApi(methodDescriptor);
    recorder.recordException(throwable);
    final ChannelHandlerContext channelHandlerContext = (ChannelHandlerContext) args[0];
    final HttpMessage httpMessage = (HttpMessage) args[1];
    this.clientRequestRecorder.record(recorder, new NettyClientRequestWrapper(httpMessage, channelHandlerContext), throwable);
}
Also used : NettyClientRequestWrapper(com.navercorp.pinpoint.plugin.netty.NettyClientRequestWrapper) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) HttpMessage(io.netty.handler.codec.http.HttpMessage)

Example 4 with HttpMessage

use of io.netty.handler.codec.http.HttpMessage in project pinpoint by naver.

the class HttpEncoderInterceptor method validate.

private boolean validate(Object[] args) {
    if (ArrayUtils.getLength(args) != 3) {
        return false;
    }
    if (!(args[0] instanceof ChannelHandlerContext)) {
        return false;
    }
    ChannelHandlerContext channelHandlerContext = (ChannelHandlerContext) args[0];
    Channel channel = channelHandlerContext.channel();
    if (channel == null) {
        return false;
    }
    if (!(args[1] instanceof HttpMessage)) {
        return false;
    }
    HttpMessage httpMessage = (HttpMessage) args[1];
    if (httpMessage.headers() == null) {
        return false;
    }
    if (!(args[1] instanceof AsyncContextAccessor)) {
        return false;
    }
    if (!(args[1] instanceof AsyncStartFlagFieldAccessor)) {
        return false;
    }
    return true;
}
Also used : Channel(io.netty.channel.Channel) AsyncContextAccessor(com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) HttpMessage(io.netty.handler.codec.http.HttpMessage) AsyncStartFlagFieldAccessor(com.navercorp.pinpoint.plugin.netty.field.accessor.AsyncStartFlagFieldAccessor)

Example 5 with HttpMessage

use of io.netty.handler.codec.http.HttpMessage in project netty by netty.

the class Http2ServerInitializer method configureClearText.

/**
 * Configure the pipeline for a cleartext upgrade from HTTP to HTTP/2.0
 */
private void configureClearText(SocketChannel ch) {
    final ChannelPipeline p = ch.pipeline();
    final HttpServerCodec sourceCodec = new HttpServerCodec();
    final HttpServerUpgradeHandler upgradeHandler = new HttpServerUpgradeHandler(sourceCodec, upgradeCodecFactory);
    final CleartextHttp2ServerUpgradeHandler cleartextHttp2ServerUpgradeHandler = new CleartextHttp2ServerUpgradeHandler(sourceCodec, upgradeHandler, new HelloWorldHttp2HandlerBuilder().build());
    p.addLast(cleartextHttp2ServerUpgradeHandler);
    p.addLast(new SimpleChannelInboundHandler<HttpMessage>() {

        @Override
        protected void channelRead0(ChannelHandlerContext ctx, HttpMessage msg) throws Exception {
            // If this handler is hit then no upgrade has been attempted and the client is just talking HTTP.
            System.err.println("Directly talking: " + msg.protocolVersion() + " (no upgrade was attempted)");
            ChannelPipeline pipeline = ctx.pipeline();
            ChannelHandlerContext thisCtx = pipeline.context(this);
            pipeline.addAfter(thisCtx.name(), null, new HelloWorldHttp1Handler("Direct. No Upgrade Attempted."));
            pipeline.replace(this, null, new HttpObjectAggregator(maxHttpContentLength));
            ctx.fireChannelRead(ReferenceCountUtil.retain(msg));
        }
    });
    p.addLast(new UserEventLogger());
}
Also used : CleartextHttp2ServerUpgradeHandler(io.netty.handler.codec.http2.CleartextHttp2ServerUpgradeHandler) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) HttpServerUpgradeHandler(io.netty.handler.codec.http.HttpServerUpgradeHandler) ChannelPipeline(io.netty.channel.ChannelPipeline) HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec) HttpMessage(io.netty.handler.codec.http.HttpMessage)

Aggregations

HttpMessage (io.netty.handler.codec.http.HttpMessage)20 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)11 ChannelPipeline (io.netty.channel.ChannelPipeline)9 HttpObjectAggregator (io.netty.handler.codec.http.HttpObjectAggregator)6 HttpServerCodec (io.netty.handler.codec.http.HttpServerCodec)6 HttpServerUpgradeHandler (io.netty.handler.codec.http.HttpServerUpgradeHandler)6 FullHttpMessage (io.netty.handler.codec.http.FullHttpMessage)4 HttpContent (io.netty.handler.codec.http.HttpContent)3 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)3 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)3 CleartextHttp2ServerUpgradeHandler (io.netty.handler.codec.http2.CleartextHttp2ServerUpgradeHandler)3 ChannelHandler (io.netty.channel.ChannelHandler)2 HelloWorldHttp1Handler (io.netty.example.http2.helloworld.server.HelloWorldHttp1Handler)2 DefaultHttpContent (io.netty.handler.codec.http.DefaultHttpContent)2 DefaultLastHttpContent (io.netty.handler.codec.http.DefaultLastHttpContent)2 HttpContentCompressor (io.netty.handler.codec.http.HttpContentCompressor)2 Http2ServerUpgradeCodec (io.netty.handler.codec.http2.Http2ServerUpgradeCodec)2 HMACAuthenticator (org.janusgraph.graphdb.tinkerpop.gremlin.server.auth.HMACAuthenticator)2 JanusGraphSimpleAuthenticator (org.janusgraph.graphdb.tinkerpop.gremlin.server.auth.JanusGraphSimpleAuthenticator)2 SaslAndHMACAuthenticator (org.janusgraph.graphdb.tinkerpop.gremlin.server.auth.SaslAndHMACAuthenticator)2