Skip to content

Commit

Permalink
Keep completed flag for retained/duplicated HttpData (#12576)
Browse files Browse the repository at this point in the history
  • Loading branch information
pderop committed Jul 8, 2022
1 parent 29b203f commit c949fa6
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 2 deletions.
Expand Up @@ -83,7 +83,11 @@ public boolean isCompleted() {
}

protected void setCompleted() {
completed = true;
setCompleted(true);
}

protected void setCompleted(boolean completed) {
this.completed = completed;
}

@Override
Expand Down
Expand Up @@ -242,6 +242,7 @@ public Attribute replace(ByteBuf content) {
throw new ChannelException(e);
}
}
attr.setCompleted(isCompleted());
return attr;
}

Expand Down
Expand Up @@ -210,6 +210,7 @@ public FileUpload replace(ByteBuf content) {
throw new ChannelException(e);
}
}
upload.setCompleted(isCompleted());
return upload;
}

Expand Down
Expand Up @@ -167,6 +167,7 @@ public Attribute replace(ByteBuf content) {
throw new ChannelException(e);
}
}
attr.setCompleted(isCompleted());
return attr;
}

Expand Down
Expand Up @@ -154,11 +154,11 @@ public FileUpload replace(ByteBuf content) {
if (content != null) {
try {
upload.setContent(content);
return upload;
} catch (IOException e) {
throw new ChannelException(e);
}
}
upload.setCompleted(isCompleted());
return upload;
}

Expand Down
Expand Up @@ -17,6 +17,7 @@

import io.netty.buffer.ByteBuf;
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.buffer.Unpooled;
import io.netty.util.CharsetUtil;
import org.assertj.core.api.ThrowableAssert;
import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -68,6 +69,20 @@ void testAddContentEmptyBuffer(HttpData httpData) throws IOException {
assertThat(content.refCnt()).isEqualTo(0);
}

@ParameterizedHttpDataTest
void testCompletedFlagPreservedAfterRetainDuplicate(HttpData httpData) throws IOException {
httpData.addContent(Unpooled.wrappedBuffer("foo".getBytes(CharsetUtil.UTF_8)), false);
assertThat(httpData.isCompleted()).isFalse();
HttpData duplicate = httpData.retainedDuplicate();
assertThat(duplicate.isCompleted()).isFalse();
assertThat(duplicate.release()).isTrue();
httpData.addContent(Unpooled.wrappedBuffer("bar".getBytes(CharsetUtil.UTF_8)), true);
assertThat(httpData.isCompleted()).isTrue();
duplicate = httpData.retainedDuplicate();
assertThat(duplicate.isCompleted()).isTrue();
assertThat(duplicate.release()).isTrue();
}

@Test
void testAddContentExceedsDefinedSizeDiskFileUpload() {
doTestAddContentExceedsSize(
Expand Down

0 comments on commit c949fa6

Please sign in to comment.