27
27
import io .netty .channel .ChannelHandlerContext ;
28
28
import io .netty .channel .ChannelPromise ;
29
29
import io .netty .handler .codec .DecoderResult ;
30
+ import io .netty .handler .codec .http .DefaultFullHttpResponse ;
30
31
import io .netty .handler .codec .http .DefaultHttpContent ;
32
+ import io .netty .handler .codec .http .DefaultHttpResponse ;
33
+ import io .netty .handler .codec .http .DefaultLastHttpContent ;
31
34
import io .netty .handler .codec .http .HttpObject ;
32
35
import io .netty .handler .codec .http .HttpRequest ;
33
36
import io .netty .handler .codec .http .HttpResponse ;
46
49
import reactor .netty .http .logging .HttpMessageLogFactory ;
47
50
import reactor .util .annotation .Nullable ;
48
51
52
+ import static io .netty .handler .codec .http .LastHttpContent .EMPTY_LAST_CONTENT ;
49
53
import static reactor .netty .ReactorNetty .format ;
50
54
51
55
/**
@@ -173,7 +177,24 @@ else if (!pendingResponse) {
173
177
@ Override
174
178
@ SuppressWarnings ("FutureReturnValueIgnored" )
175
179
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 ) {
177
198
if (!pendingResponse ) {
178
199
if (HttpServerOperations .log .isDebugEnabled ()) {
179
200
HttpServerOperations .log .debug (
@@ -195,9 +216,13 @@ else if (msg instanceof HttpResponse && HttpResponseStatus.CONTINUE.code() == ((
195
216
//"FutureReturnValueIgnored" this is deliberate
196
217
ctx .write (msg , promise );
197
218
if (msg instanceof LastHttpContent ) {
198
- pendingResponse = false ;
199
- ctx .read ();
219
+ finalizeResponse (ctx );
200
220
}
201
221
}
202
222
}
223
+
224
+ void finalizeResponse (ChannelHandlerContext ctx ) {
225
+ pendingResponse = false ;
226
+ ctx .read ();
227
+ }
203
228
}
0 commit comments