aws-sdk-js-v3
aws-sdk-js-v3 copied to clipboard
Throw specific error if Content-Length can't be computed
Is your feature request related to a problem? Please describe.
S3 throws NotImplemented
Error in Content-Length can't be computed in https://github.com/aws/aws-sdk-js-v3/issues/3377
The error can be more specific, i.e. Content-Length can't be computed.
Describe the solution you'd like
Throw error in calculateBodyLength
if length can't be computed.
- https://github.com/aws/aws-sdk-js-v3/blob/main/packages%2Futil-body-length-node%2Fsrc%2FcalculateBodyLength.ts
- https://github.com/aws/aws-sdk-js-v3/blob/main/packages%2Futil-body-length-browser%2Fsrc%2FcalculateBodyLength.ts
Describe alternatives you've considered
N/A
Additional context
This suggestion was discussed and approved internally.
As of now, the contentLengthMiddleware skips setting Content-Length
header if it is undefined.
https://github.com/aws/aws-sdk-js-v3/blob/88f8cc2d3d33f4dc6d06312e75f70725c89d1f17/packages/middleware-content-length/src/index.ts#L27-L33
From rfc7230 specification 3.3.2
A user agent SHOULD send a Content-Length in a request message when no Transfer-Encoding is sent and the request method defines a meaning for an enclosed payload body. For example, a Content-Length header field is normally sent in a POST request even when the value is 0 (indicating an empty payload body). A user agent SHOULD NOT send a Content-Length header field when the request message does not contain a payload body and the method semantics do not anticipate such a body.
The contentLengthMiddleware checks if body is defined and Content-Length header is not set before calling bodyLengthChecker. And as per spec it should be fine to throw error if bodyLengthChecker, as user agent should send a Content-Length in case of enclosed payload body.
I've asked this question on internal Slack channel to check behaviors in other SDKs, and will revisit this feature request in future.
The AWS SDK for Python and CLI sets Transfer-Encoding
to chunked
if they're not able to determine content-length
https://github.com/boto/botocore/blob/354e9cb22017112a6f72fb20c36b133c9f346002/botocore/awsrequest.py#L364-L374
Greetings! We’re closing this issue because it has been open a long time and hasn’t been updated in a while and may not be getting the attention it deserves. We encourage you to check if this is still an issue in the latest release and if you find that this is still a problem, please feel free to comment or open a new issue.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.