Skip to content

Commit 08b58be

Browse files
authored
Simplify Http2StreamBridgeServerHandler#write (#3391)
1 parent 57a842d commit 08b58be

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

reactor-netty-http/src/main/java/reactor/netty/http/server/Http2StreamBridgeServerHandler.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@
2727
import io.netty.channel.ChannelHandlerContext;
2828
import io.netty.channel.ChannelPromise;
2929
import io.netty.handler.codec.DecoderResult;
30+
import io.netty.handler.codec.http.DefaultFullHttpResponse;
3031
import io.netty.handler.codec.http.DefaultHttpContent;
32+
import io.netty.handler.codec.http.DefaultHttpResponse;
33+
import io.netty.handler.codec.http.DefaultLastHttpContent;
3134
import io.netty.handler.codec.http.HttpObject;
3235
import io.netty.handler.codec.http.HttpRequest;
3336
import io.netty.handler.codec.http.HttpResponse;
@@ -46,6 +49,7 @@
4649
import reactor.netty.http.logging.HttpMessageLogFactory;
4750
import reactor.util.annotation.Nullable;
4851

52+
import static io.netty.handler.codec.http.LastHttpContent.EMPTY_LAST_CONTENT;
4953
import static reactor.netty.ReactorNetty.format;
5054

5155
/**
@@ -173,7 +177,24 @@ else if (!pendingResponse) {
173177
@Override
174178
@SuppressWarnings("FutureReturnValueIgnored")
175179
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) {
176-
if (msg instanceof ByteBuf) {
180+
Class<?> msgClass = msg.getClass();
181+
if (msgClass == DefaultHttpResponse.class) {
182+
//"FutureReturnValueIgnored" this is deliberate
183+
ctx.write(msg, promise);
184+
}
185+
else if (msgClass == DefaultFullHttpResponse.class) {
186+
//"FutureReturnValueIgnored" this is deliberate
187+
ctx.write(msg, promise);
188+
if (HttpResponseStatus.CONTINUE.code() == ((DefaultFullHttpResponse) msg).status().code()) {
189+
return;
190+
}
191+
finalizeResponse(ctx);
192+
}
193+
else if (msg == EMPTY_LAST_CONTENT || msgClass == DefaultLastHttpContent.class) {
194+
ctx.write(msg, promise);
195+
finalizeResponse(ctx);
196+
}
197+
else if (msg instanceof ByteBuf) {
177198
if (!pendingResponse) {
178199
if (HttpServerOperations.log.isDebugEnabled()) {
179200
HttpServerOperations.log.debug(
@@ -195,9 +216,13 @@ else if (msg instanceof HttpResponse && HttpResponseStatus.CONTINUE.code() == ((
195216
//"FutureReturnValueIgnored" this is deliberate
196217
ctx.write(msg, promise);
197218
if (msg instanceof LastHttpContent) {
198-
pendingResponse = false;
199-
ctx.read();
219+
finalizeResponse(ctx);
200220
}
201221
}
202222
}
223+
224+
void finalizeResponse(ChannelHandlerContext ctx) {
225+
pendingResponse = false;
226+
ctx.read();
227+
}
203228
}

0 commit comments

Comments
 (0)