Handle checksum for unseekable 0-length s3 request body #3086
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Fixes #3080
The SDK calculates checksums differently depending on whether the request body can be rewinded (is seekable) or not. Bodies that we cannot rewind have to use trailing checksums, where we follow a different algorithm to calculate the checksum.
We had an issue where we treated any 0 content-length as "content length unknown", when in reality the sentinel value for not set is -1. Due to this, the SDK would
getRequestStreamLength(-1 instead of the 0 set by the customer)This has changed now so we actually treat
0as a valid value and we send the right content header.Wait, didn't we already have a test for this?
Yes! as you can see, we have a test named
https empty stream unseekable. However, there are some nuances on how these requests are actually treated when we callSetStream. The test used to havebytes.Buffer, whose length can be identified by usingLen(). This makes it take a different path on the underlying implementationso it's treated as seekable later on the implementation. Changed the tests to fix this