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);
}
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);
}
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);
}
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);
}
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());
}
Aggregations