Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep completed flag for retained/duplicated HttpData #12576

Merged
merged 1 commit into from Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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