Skip to content

Fixed for #409 "MultipartBody generates wrong body bytes" and added the ... #410

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

Merged
merged 2 commits into from
Nov 6, 2013

Conversation

carryel
Copy link
Contributor

@carryel carryel commented Nov 6, 2013

Proposed patch based on ahc-1.7.x branch.

Current sources may be failed in MultipartBodyTest.java so you can reproduce this issue with the testcase.
If you need the patch based on master, please let me know!

(Note) This code/patch should be applied after resolving issue AsyncHttpClient#409 "MultipartBody generates wrong body bytes"
ByteArrayOutputStream output = new ByteArrayOutputStream();
Part.sendPart(output, filePart, boundary);
final ByteArrayOutputStream output = new ByteArrayOutputStream();
filePart.sendData(output);
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't filePart.sendEnd(output); missing there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, filePart.sendEnd(output) is not needed at this line. filePart.sendEnd(output) will be called at initializeFileEnd() --> generateFileEnd().

Copy link
Contributor

Choose a reason for hiding this comment

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

You're right.

@slandelle
Copy link
Contributor

@rlubke Could you review the Grizzly part, please?

@@ -78,7 +78,10 @@ public long read(ByteBuffer buffer) throws IOException {
try {
int overallLength = 0;

int maxLength = buffer.capacity();
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, I don't think there's a real problem here: the ByteBuffer passed from either Netty and Grizzly providers is a freshly allocated one, so remaining equals capacity. Also, it cannot be negative (it's the chunk size).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

About capacity(), grizzly provider's pure allocation and converting grizzly's Buffer to ByteBuffer doesn't guarantee remaining equals capacity. When I tested the ByteBuffer's capacity is larger than limit(at the pos is 0). If capacity() should be used, maybe ByteBuffer#slice() will be needed after allocation.

For your help, here are grizzly provider's javadoc for Buffer(allocation and converting to ByteBuffer).


/**
 * <p>
 * Converts this <code>Buffer</code> to a {@link ByteBuffer}.
 * If this <code>Buffer</code> is not composite - then returned
 * {@link ByteBuffer}'s content is a shared subsequence of this buffer's
 * content, with {@link CompositeBuffer} this is not guaranteed.
 * The position of the returned {@link ByteBuffer} is not guaranteed to be 0,
 * the capacity of the returned {@link ByteBuffer} is not guaranteed to be
 * equal to the capacity of this <code>Buffer</code>.
 * It is guaranteed that the result of the returned ByteBuffer's
 * {@link ByteBuffer#remaining()} call will be equal to this Buffer's
 * {@link #remaining()} call.
 * The Buffer's and ByteBuffer's position, limit, and mark values are not
 * guaranteed to be independent, so it's recommended to save and restore
 * position, limit values if it is planned to change them or
 * {@link ByteBuffer#slice()} the returned {@link ByteBuffer}.
 * <p/>
 *
 * @return this <code>Buffer</code> as a {@link ByteBuffer}.
 */
ByteBuffer toByteBuffer();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

About negative, I agreed!

rlubke added a commit that referenced this pull request Nov 6, 2013
Fixed for #409 "MultipartBody generates wrong body bytes" and added the ...
@rlubke rlubke merged commit cf6509a into AsyncHttpClient:ahc-1.7.x Nov 6, 2013
@carryel
Copy link
Contributor Author

carryel commented Nov 7, 2013

@rlubke for your convenience, I will pull a request again for master branch.

cs-workco pushed a commit to cs-workco/async-http-client that referenced this pull request Apr 13, 2023
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.

3 participants