@@ -35,7 +35,6 @@ public class NettyHandler extends ChannelInboundHandlerAdapter {
3535 private final boolean defaultHeaders ;
3636 private final long maxRequestSize ;
3737 private final int maxFormFields ;
38- private long contentLength ;
3938 private long chunkSize ;
4039 private final boolean http2 ;
4140 private NettyContext context ;
@@ -78,7 +77,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) {
7877 router .match (context ).execute (context );
7978 } else {
8079 // possibly body:
81- contentLength = contentLength (req );
80+ long contentLength = contentLength (req );
8281 if (contentLength > 0 || isTransferEncodingChunked (req )) {
8382 context .httpDataFactory = new DefaultHttpDataFactory (bufferSize );
8483 context .httpDataFactory .setBaseDir (app .getTmpdir ().toString ());
@@ -88,20 +87,6 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) {
8887 router .match (context ).execute (context );
8988 }
9089 }
91- } else if (isLastHttpContent (msg )) {
92- var chunk = (HttpContent ) msg ;
93- try {
94- // when decoder == null, chunk is always a LastHttpContent.EMPTY, ignore it
95- if (context .decoder != null ) {
96- if (offer (context , chunk )) {
97- Router .Match route = router .match (context );
98- resetDecoderState (context , !route .matches ());
99- route .execute (context );
100- }
101- }
102- } finally {
103- release (chunk );
104- }
10590 } else if (isHttpContent (msg )) {
10691 var chunk = (HttpContent ) msg ;
10792 try {
@@ -113,10 +98,13 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) {
11398 router .match (context ).execute (context , Route .REQUEST_ENTITY_TOO_LARGE );
11499 return ;
115100 }
116- offer (context , chunk );
101+ if (offer (context , chunk ) && isLastHttpContent (msg )) {
102+ Router .Match route = router .match (context );
103+ resetDecoderState (context , !route .matches ());
104+ route .execute (context );
105+ }
117106 }
118107 } finally {
119- // must be released
120108 release (chunk );
121109 }
122110 } else if (isWebSocketFrame (msg )) {
@@ -191,7 +179,6 @@ private boolean offer(NettyContext context, HttpContent chunk) {
191179
192180 private void resetDecoderState (NettyContext context , boolean destroy ) {
193181 chunkSize = 0 ;
194- contentLength = -1 ;
195182 if (destroy && context .decoder != null ) {
196183 var decoder = context .decoder ;
197184 var httpDataFactory = context .httpDataFactory ;
0 commit comments