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