File tree Expand file tree Collapse file tree 6 files changed +24
-2
lines changed
main/java/io/netty/handler/codec/http/multipart
test/java/io/netty/handler/codec/http/multipart Expand file tree Collapse file tree 6 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -83,7 +83,11 @@ public boolean isCompleted() {
8383 }
8484
8585 protected void setCompleted () {
86- completed = true ;
86+ setCompleted (true );
87+ }
88+
89+ protected void setCompleted (boolean completed ) {
90+ this .completed = completed ;
8791 }
8892
8993 @ Override
Original file line number Diff line number Diff line change @@ -242,6 +242,7 @@ public Attribute replace(ByteBuf content) {
242242 throw new ChannelException (e );
243243 }
244244 }
245+ attr .setCompleted (isCompleted ());
245246 return attr ;
246247 }
247248
Original file line number Diff line number Diff line change @@ -210,6 +210,7 @@ public FileUpload replace(ByteBuf content) {
210210 throw new ChannelException (e );
211211 }
212212 }
213+ upload .setCompleted (isCompleted ());
213214 return upload ;
214215 }
215216
Original file line number Diff line number Diff line change @@ -167,6 +167,7 @@ public Attribute replace(ByteBuf content) {
167167 throw new ChannelException (e );
168168 }
169169 }
170+ attr .setCompleted (isCompleted ());
170171 return attr ;
171172 }
172173
Original file line number Diff line number Diff line change @@ -154,11 +154,11 @@ public FileUpload replace(ByteBuf content) {
154154 if (content != null ) {
155155 try {
156156 upload .setContent (content );
157- return upload ;
158157 } catch (IOException e ) {
159158 throw new ChannelException (e );
160159 }
161160 }
161+ upload .setCompleted (isCompleted ());
162162 return upload ;
163163 }
164164
Original file line number Diff line number Diff line change 1717
1818import io .netty .buffer .ByteBuf ;
1919import io .netty .buffer .PooledByteBufAllocator ;
20+ import io .netty .buffer .Unpooled ;
2021import io .netty .util .CharsetUtil ;
2122import org .assertj .core .api .ThrowableAssert ;
2223import org .junit .jupiter .api .BeforeAll ;
@@ -68,6 +69,20 @@ void testAddContentEmptyBuffer(HttpData httpData) throws IOException {
6869 assertThat (content .refCnt ()).isEqualTo (0 );
6970 }
7071
72+ @ ParameterizedHttpDataTest
73+ void testCompletedFlagPreservedAfterRetainDuplicate (HttpData httpData ) throws IOException {
74+ httpData .addContent (Unpooled .wrappedBuffer ("foo" .getBytes (CharsetUtil .UTF_8 )), false );
75+ assertThat (httpData .isCompleted ()).isFalse ();
76+ HttpData duplicate = httpData .retainedDuplicate ();
77+ assertThat (duplicate .isCompleted ()).isFalse ();
78+ assertThat (duplicate .release ()).isTrue ();
79+ httpData .addContent (Unpooled .wrappedBuffer ("bar" .getBytes (CharsetUtil .UTF_8 )), true );
80+ assertThat (httpData .isCompleted ()).isTrue ();
81+ duplicate = httpData .retainedDuplicate ();
82+ assertThat (duplicate .isCompleted ()).isTrue ();
83+ assertThat (duplicate .release ()).isTrue ();
84+ }
85+
7186 @ Test
7287 void testAddContentExceedsDefinedSizeDiskFileUpload () {
7388 doTestAddContentExceedsSize (
You can’t perform that action at this time.
0 commit comments