@Override protected void requestDemand() { bodyRequested(ctx); super.requestDemand(); } };
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { // Set to false, since if it was true, and the client is sending data, then the // client must no longer be expecting it (due to a timeout, for example). continueExpected = false; sendContinue = false; if (msg instanceof HttpRequest) { HttpRequest request = (HttpRequest) msg; lastRequest = request; if (HttpUtil.is100ContinueExpected(request)) { continueExpected = true; } } super.channelRead(ctx, msg); }
private void completeBody(final ChannelHandlerContext ctx) { removeHandlerIfActive(ctx, ctx.name() + "-body-subscriber"); if (sendLastHttpContent) { ChannelPromise promise = outgoing.peek().promise; ctx.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT, promise).addListener( (ChannelFutureListener) channelFuture -> executeInEventLoop(ctx, () -> { outgoing.remove(); sentOutMessage(ctx); flushNext(ctx); }) ); ctx.read(); } else { outgoing.remove().promise.setSuccess(); sentOutMessage(ctx); flushNext(ctx); ctx.read(); } }
@Override public void write(final ChannelHandlerContext ctx, Object msg, final ChannelPromise promise) throws Exception { if (isValidOutMessage(msg)) { Outgoing out = new Outgoing(outClass.cast(msg), promise); receivedOutMessage(ctx); if (outgoing.isEmpty()) { outgoing.add(out); flushNext(ctx); } else { outgoing.add(out); } } else if (msg instanceof LastHttpContent) { sendLastHttpContent = false; ctx.write(msg, promise); } else { ctx.write(msg, promise); } }
@Override public void channelRead(final ChannelHandlerContext ctx, Object msg) throws Exception { if (isValidInMessage(msg)) { receivedInMessage(ctx); final In inMsg = inClass.cast(msg); consumedInMessage(ctx); } else if (!hasBody(inMsg)) { ctx.fireChannelRead(createEmptyMessage(inMsg)); consumedInMessage(ctx); ctx.fireChannelRead(createStreamedMessage(inMsg, publisher)); handleReadHttpContent(ctx, (HttpContent) msg);
out.promise.addListener((ChannelFutureListener) channelFuture -> executeInEventLoop(ctx, () -> { sentOutMessage(ctx); outgoing.remove(); flushNext(ctx); })); subscribeSubscriberToStream(streamed, subscriber);
private void handleReadHttpContent(ChannelHandlerContext ctx, HttpContent content) { if (!ignoreBodyRead) { if (content instanceof LastHttpContent) { if (content.content().readableBytes() > 0 || !((LastHttpContent) content).trailingHeaders().isEmpty()) { // It has data or trailing headers, send them ctx.fireChannelRead(content); } else { ReferenceCountUtil.release(content); } removeHandlerIfActive(ctx, ctx.name() + "-body-publisher"); currentlyStreamedMessage = null; consumedInMessage(ctx); } else { ctx.fireChannelRead(content); } } else { ReferenceCountUtil.release(content); if (content instanceof LastHttpContent) { ignoreBodyRead = false; if (currentlyStreamedMessage != null) { removeHandlerIfActive(ctx, ctx.name() + "-body-publisher"); } currentlyStreamedMessage = null; } } }
HttpResponse response = (HttpResponse) msg; if (response.status().equals(HttpResponseStatus.CONTINUE)) { super.subscribeSubscriberToStream(awaiting100ContinueMessage, awaiting100Continue); awaiting100Continue = null; awaiting100ContinueMessage = null; awaiting100Continue.onComplete(); awaiting100Continue = null; super.channelRead(ctx, msg); super.channelRead(ctx, msg);
@Override public void handlerRemoved(ChannelHandlerContext ctx) throws Exception { super.handlerRemoved(ctx); for (ChannelHandler dependent : dependentHandlers) { try { ctx.pipeline().remove(dependent); } catch (NoSuchElementException e) { // Ignore, maybe something else removed it } } } }