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

Fix fetching body content after buffer has been read #1778

Merged
merged 2 commits into from
May 24, 2024

Conversation

gavinbunney
Copy link
Contributor

@gavinbunney gavinbunney commented May 23, 2024

When fetching the body content of a ZuulMessage, the returned content differs based on if the body content chunks have been read, i.e. after it has been proxied to an upstream origin.

This change uses the writerIndex to instead track the total number of readable bytes of the bytebuf, so the entire content is always returned by the getBody* methods.

final byte[] body = new byte[size];
int offset = 0;
for (final HttpContent chunk : bodyChunks) {
final ByteBuf content = chunk.content();
final int len = content.readableBytes();
content.getBytes(content.readerIndex(), body, offset, len);
final int len = content.writerIndex(); // writer idx tracks the total readable bytes in the buffer
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do this, let's at least indicate in the comments that the API shall always return the complete buffered body, and not the pending readable bytes. Same for getBodyLength()

@gavinbunney gavinbunney merged commit 5f10b9a into master May 24, 2024
5 checks passed
@gavinbunney gavinbunney deleted the gavin/body-buff branch May 24, 2024 01:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants