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: remove extraneous content encoding #650

Closed
wants to merge 15 commits into from

Conversation

chingor13
Copy link
Collaborator

@chingor13 chingor13 commented May 24, 2019

Fixes #648

In order to calculate the content length, we must write the encoded the
data first. The encoded data is written to a buffer using a
ByteArrayOutputStream implementation and we use that to figure out how
many bytes of data is to be sent.

Previously, this data was thrown away and the content was re-encoded
when it was actually time to send the data.

Instead, we now replace the content with a ByteArrayContent which
contains the buffer we wrote to when calculating the size.

We implemented a new CachingByteArrayOutputStream so that we can access
the byte buffer directly rather than copying into a new byte array (for
memory performance)

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label May 24, 2019
@chingor13 chingor13 added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 24, 2019
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 24, 2019
In order to calculate the contentLength, we must write the encode the
data first. The encoded data is written to a buffer using a
ByteArrayOutputStream implementation and we use that to figure out how
many bytes of data is to be sent.

Previously, this data was thrown away and the content was re-encoded
when it was actually time to send the data.

Instead, we now replace the content with a ByteArrayContent which
contains the buffer we wrote to when calculating the size.

We implemented a new CachingByteArrayOutputStream so that we can access
the byte buffer directly rather than copying into a new byte array (for
memory performance)
@chingor13 chingor13 marked this pull request as ready for review May 24, 2019 17:53
@chingor13 chingor13 requested a review from a team as a code owner May 24, 2019 17:53
We really only care that the contents was encode and is correctly
marked as such.
* Fix javadoc param name

* Group serializeHeaders() overloads
* Remove deprecated google-http-client-jackson artifact.

Jackson 1.x has been unsupported for a long time. Users should be using
Jackson 2.x. the google-http-client-jackson artifact was deprecated in
1.28.0.

* Fix assembly references to jackson
* Add Base64Test case for some base64 decoding edge cases

* Preserve decoding behavior for null decodeBase64(null)

* Handle encoding with null inputs
@@ -932,7 +932,14 @@ public HttpResponse execute() throws IOException {
} else {
contentEncoding = encoding.getName();
streamingContent = new HttpEncodingStreamingContent(streamingContent, encoding);
contentLength = contentRetrySupported ? IOUtils.computeLength(streamingContent) : -1;
if (contentRetrySupported) {
CachingByteArrayOutputStream outputStream = new CachingByteArrayOutputStream();
Copy link
Contributor

Choose a reason for hiding this comment

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

IOUtils checks the size via streaming, and doesn't actually store the data in memory. The same thing for sending the data. A large object will currently never fully have to be in memory.

This change may cause an unexpected memory spike for users with large objects

@ludoch
Copy link

ludoch commented May 29, 2019

Since this bug was filed on the GAE standard product, memory management is critical as we do not have big mems on instance classes machines...
A test in this env would be welcome (request size limit is 32Mb, compressed or not IIUC).

@chingor13
Copy link
Collaborator Author

As is, this implementation won't be good enough

@chingor13 chingor13 added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label May 29, 2019
renovate-bot and others added 8 commits May 31, 2019 10:55
In order to calculate the contentLength, we must write the encode the
data first. The encoded data is written to a buffer using a
ByteArrayOutputStream implementation and we use that to figure out how
many bytes of data is to be sent.

Previously, this data was thrown away and the content was re-encoded
when it was actually time to send the data.

Instead, we now replace the content with a ByteArrayContent which
contains the buffer we wrote to when calculating the size.

We implemented a new CachingByteArrayOutputStream so that we can access
the byte buffer directly rather than copying into a new byte array (for
memory performance)
We really only care that the contents was encode and is correctly
marked as such.
@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of all the commit author(s), set the cla label to yes (if enabled on your project), and then merge this pull request when appropriate.

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: no This human has *not* signed the Contributor License Agreement. and removed cla: yes This human has signed the Contributor License Agreement. labels Jun 3, 2019
@chingor13 chingor13 closed this Jun 3, 2019
clundin25 pushed a commit to clundin25/google-http-java-client that referenced this pull request Aug 11, 2022
IdtokenProvider implementation for UserCredentials with unit tests for idtoken
clundin25 pushed a commit to clundin25/google-http-java-client that referenced this pull request Aug 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: no This human has *not* signed the Contributor License Agreement. do not merge Indicates a pull request not ready for merge, due to either quality or timing.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HttpContent is encoded two times when posting data
6 participants