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

Throw specific error if Content-Length can't be computed #3400

Closed
trivikr opened this issue Mar 8, 2022 · 6 comments
Closed

Throw specific error if Content-Length can't be computed #3400

trivikr opened this issue Mar 8, 2022 · 6 comments
Labels
closed-for-staleness feature-request New feature or enhancement. May require GitHub community feedback. p2 This is a standard priority issue

Comments

@trivikr
Copy link
Member

trivikr commented Mar 8, 2022

Is your feature request related to a problem? Please describe.

S3 throws NotImplemented Error in Content-Length can't be computed in #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.

Describe alternatives you've considered

N/A

Additional context

This suggestion was discussed and approved internally.

@trivikr trivikr added the feature-request New feature or enhancement. May require GitHub community feedback. label Mar 8, 2022
@trivikr
Copy link
Member Author

trivikr commented Mar 8, 2022

As of now, the contentLengthMiddleware skips setting Content-Length header if it is undefined.

const length = bodyLengthChecker(body);
if (length !== undefined) {
request.headers = {
...request.headers,
[CONTENT_LENGTH_HEADER]: String(length),
};
}

@trivikr
Copy link
Member Author

trivikr commented Mar 8, 2022

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.

@trivikr
Copy link
Member Author

trivikr commented Mar 8, 2022

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.

@trivikr
Copy link
Member Author

trivikr commented Mar 8, 2022

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

@github-actions
Copy link

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.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Sep 15, 2023
@github-actions
Copy link

github-actions bot commented Oct 3, 2023

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
closed-for-staleness feature-request New feature or enhancement. May require GitHub community feedback. p2 This is a standard priority issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants