Search in sources :

Example 11 with HttpMessage

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

the class ProxyConnection method readHTTP.

@SuppressWarnings("unchecked")
private void readHTTP(HttpObject httpObject) {
    ConnectionState nextState = getCurrentState();
    switch(getCurrentState()) {
        case AWAITING_INITIAL:
            if (httpObject instanceof HttpMessage) {
                nextState = readHTTPInitial((I) httpObject);
            } else {
                LOG.debug("Dropping message because HTTP object was not an HttpMessage. HTTP object may be orphaned content from a short-circuited response. Message: {}", httpObject);
            }
            break;
        case AWAITING_CHUNK:
            HttpContent chunk = (HttpContent) httpObject;
            readHTTPChunk(chunk);
            nextState = ProxyUtils.isLastChunk(chunk) ? AWAITING_INITIAL : AWAITING_CHUNK;
            break;
        case AWAITING_PROXY_AUTHENTICATION:
            if (httpObject instanceof HttpRequest) {
                nextState = readHTTPInitial((I) httpObject);
            } else {
            }
            break;
        case CONNECTING:
            LOG.warn("Attempted to read from connection that's in the process of connecting.  This shouldn't happen.");
            break;
        case NEGOTIATING_CONNECT:
            LOG.debug("Attempted to read from connection that's in the process of negotiating an HTTP CONNECT.  This is probably the LastHttpContent of a chunked CONNECT.");
            break;
        case AWAITING_CONNECT_OK:
            LOG.warn("AWAITING_CONNECT_OK should have been handled by ProxyToServerConnection.read()");
            break;
        case HANDSHAKING:
            LOG.warn("Attempted to read from connection that's in the process of handshaking.  This shouldn't happen.", channel);
            break;
        case DISCONNECT_REQUESTED:
        case DISCONNECTED:
            LOG.info("Ignoring message since the connection is closed or about to close");
            break;
    }
    become(nextState);
}
Also used : HttpRequest(io.netty.handler.codec.http.HttpRequest) ConnectionState(io.github.tesla.gateway.netty.transmit.ConnectionState) HttpMessage(io.netty.handler.codec.http.HttpMessage) HttpContent(io.netty.handler.codec.http.HttpContent)

Example 12 with HttpMessage

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

the class SocketIOChannelInitializer method addSocketioHandlers.

/**
 * Adds the socketio channel handlers
 *
 * @param pipeline - channel pipeline
 */
protected void addSocketioHandlers(ChannelPipeline pipeline) {
    pipeline.addLast(HTTP_REQUEST_DECODER, new HttpRequestDecoder());
    pipeline.addLast(HTTP_AGGREGATOR, new HttpObjectAggregator(configuration.getMaxHttpContentLength()) {

        @Override
        protected Object newContinueResponse(HttpMessage start, int maxContentLength, ChannelPipeline pipeline) {
            return null;
        }
    });
    pipeline.addLast(HTTP_ENCODER, new HttpResponseEncoder());
    if (configuration.isHttpCompression()) {
        pipeline.addLast(HTTP_COMPRESSION, new HttpContentCompressor());
    }
    pipeline.addLast(PACKET_HANDLER, packetHandler);
    pipeline.addLast(AUTHORIZE_HANDLER, authorizeHandler);
    pipeline.addLast(XHR_POLLING_TRANSPORT, xhrPollingTransport);
    // TODO use single instance when https://github.com/netty/netty/issues/4755 will be resolved
    if (configuration.isWebsocketCompression()) {
        pipeline.addLast(WEB_SOCKET_TRANSPORT_COMPRESSION, new WebSocketServerCompressionHandler());
    }
    pipeline.addLast(WEB_SOCKET_TRANSPORT, webSocketTransport);
    pipeline.addLast(SOCKETIO_ENCODER, encoderHandler);
    pipeline.addLast(WRONG_URL_HANDLER, wrongUrlHandler);
}
Also used : HttpResponseEncoder(io.netty.handler.codec.http.HttpResponseEncoder) HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) HttpRequestDecoder(io.netty.handler.codec.http.HttpRequestDecoder) HttpContentCompressor(io.netty.handler.codec.http.HttpContentCompressor) WebSocketServerCompressionHandler(io.netty.handler.codec.http.websocketx.extensions.compression.WebSocketServerCompressionHandler) HttpMessage(io.netty.handler.codec.http.HttpMessage) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 13 with HttpMessage

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

the class HttpEncoderInterceptor method before0.

private void before0(Trace trace, Object target, Object[] args) {
    if (!trace.canSampled()) {
        final HttpMessage httpMessage = (HttpMessage) args[1];
        this.requestTraceWriter.write(httpMessage);
        return;
    }
    final SpanEventRecorder recorder = trace.traceBlockBegin();
    doInBeforeTrace(recorder, trace, target, args);
}
Also used : SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) HttpMessage(io.netty.handler.codec.http.HttpMessage)

Example 14 with HttpMessage

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

the class SpdyClientStreamIdHandler method write.

@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) {
    if (acceptOutboundMessage(msg)) {
        HttpMessage httpMsg = (HttpMessage) msg;
        if (!httpMsg.headers().contains(SpdyHttpHeaders.Names.STREAM_ID)) {
            httpMsg.headers().setInt(Names.STREAM_ID, currentStreamId);
            // Client stream IDs are always odd
            currentStreamId += 2;
        }
    }
    ctx.write(msg, promise);
}
Also used : HttpMessage(io.netty.handler.codec.http.HttpMessage)

Example 15 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();
    p.addLast(sourceCodec);
    p.addLast(new HttpServerUpgradeHandler(sourceCodec, upgradeCodecFactory));
    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();
            pipeline.addAfter(ctx.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 : HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) HelloWorldHttp1Handler(io.netty.example.http2.helloworld.server.HelloWorldHttp1Handler) HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) HttpServerUpgradeHandler(io.netty.handler.codec.http.HttpServerUpgradeHandler) HttpMessage(io.netty.handler.codec.http.HttpMessage) ChannelPipeline(io.netty.channel.ChannelPipeline)

Aggregations

HttpMessage (io.netty.handler.codec.http.HttpMessage)19 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)10 ChannelPipeline (io.netty.channel.ChannelPipeline)8 HttpObjectAggregator (io.netty.handler.codec.http.HttpObjectAggregator)5 HttpServerCodec (io.netty.handler.codec.http.HttpServerCodec)5 HttpServerUpgradeHandler (io.netty.handler.codec.http.HttpServerUpgradeHandler)5 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 Test (org.junit.Test)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 CleartextHttp2ServerUpgradeHandler (io.netty.handler.codec.http2.CleartextHttp2ServerUpgradeHandler)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 AsyncContextAccessor (com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor)1