Set Content-Length when the request body is set instead of via middleware - #694
Set Content-Length when the request body is set instead of via middleware#694Tongs2000 wants to merge 2 commits into
Conversation
…ware Add Request.SetStreamWithLength, which sets ContentLength when the stream length is known. The protocol serializers and request compression now use it, so the SDK no longer needs the standalone ComputeContentLength middleware. That middleware is kept but deprecated.
|
Why the new API, why not just augment SetStream to do this? There already seems to be some logic that checks the stream length for something else there, even. |
Some middlewares in the |
|
Do you have an example? |
Yes. Like the request/response logging middleware, in its |
|
I'm not entirely sure why that extra SetStream call is there, but regardless, why would it be a problem to re-set content length there? |
Double checked, you are right. Besides For Both pass a body whose length can't be determined. So, moving the length logic into |
Per review, SetStream now sets ContentLength when the stream length can be determined, instead of adding a separate SetStreamWithLength method.
Issue #, if available:
Description of changes:
Request.SetStreamnow setsContentLengthwhen the stream length can be determined, so the SDK no longer needs the standaloneComputeContentLengthmiddleware. That middleware is kept but deprecated.The length is set when the body is a known-length reader such as a bytes or strings reader or a seekable stream. When the length cannot be determined, for example a non-seekable stream,
ContentLengthis left unchanged so a user-provided value is preserved. Request compression updates the length after rewriting the body.This is paired with the aws-sdk-go-v2 change (aws/aws-sdk-go-v2#3513) that stops registering
ComputeContentLengthand regenerates clients.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.