Skip to content

Commit

Permalink
Simplify Http2StreamBridgeServerHandler#write (#3391)
Browse files Browse the repository at this point in the history
  • Loading branch information
violetagg authored Aug 9, 2024
1 parent 57a842d commit 08b58be
Showing 1 changed file with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise;
import io.netty.handler.codec.DecoderResult;
import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.DefaultHttpContent;
import io.netty.handler.codec.http.DefaultHttpResponse;
import io.netty.handler.codec.http.DefaultLastHttpContent;
import io.netty.handler.codec.http.HttpObject;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpResponse;
Expand All @@ -46,6 +49,7 @@
import reactor.netty.http.logging.HttpMessageLogFactory;
import reactor.util.annotation.Nullable;

import static io.netty.handler.codec.http.LastHttpContent.EMPTY_LAST_CONTENT;
import static reactor.netty.ReactorNetty.format;

/**
Expand Down Expand Up @@ -173,7 +177,24 @@ else if (!pendingResponse) {
@Override
@SuppressWarnings("FutureReturnValueIgnored")
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) {
if (msg instanceof ByteBuf) {
Class<?> msgClass = msg.getClass();
if (msgClass == DefaultHttpResponse.class) {
//"FutureReturnValueIgnored" this is deliberate
ctx.write(msg, promise);
}
else if (msgClass == DefaultFullHttpResponse.class) {
//"FutureReturnValueIgnored" this is deliberate
ctx.write(msg, promise);
if (HttpResponseStatus.CONTINUE.code() == ((DefaultFullHttpResponse) msg).status().code()) {
return;
}
finalizeResponse(ctx);
}
else if (msg == EMPTY_LAST_CONTENT || msgClass == DefaultLastHttpContent.class) {
ctx.write(msg, promise);
finalizeResponse(ctx);
}
else if (msg instanceof ByteBuf) {
if (!pendingResponse) {
if (HttpServerOperations.log.isDebugEnabled()) {
HttpServerOperations.log.debug(
Expand All @@ -195,9 +216,13 @@ else if (msg instanceof HttpResponse && HttpResponseStatus.CONTINUE.code() == ((
//"FutureReturnValueIgnored" this is deliberate
ctx.write(msg, promise);
if (msg instanceof LastHttpContent) {
pendingResponse = false;
ctx.read();
finalizeResponse(ctx);
}
}
}

void finalizeResponse(ChannelHandlerContext ctx) {
pendingResponse = false;
ctx.read();
}
}

0 comments on commit 08b58be

Please sign in to comment.