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

Calculate content-length for SSDKs #386

Merged

Conversation

JordonPhillips
Copy link
Contributor

@JordonPhillips JordonPhillips commented Jul 19, 2021

This updates SSDK generation so that content-length is properly calculated. The existing functionality for clients couldn't be re-used because it is designed to function as a middleware that runs just before the request is sent. That makes sense for the client, because a middleware could be modifying the body. But since the SSDK doesn't have middleware, we just embed it directly.

Related PR that makes associated tests run once more (though they'll fail until this is merged): aws/aws-sdk-js-v3#2599

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

This updates SSDK generation so that content-length is properly
calculated. The existing functionality for clients couldn't be
re-used because it is designed to function as a middleware that runs
just beforee the request is sent. That makes sense for the client,
because a middleware could be modifying the body. But since the SSDK
doesn't have middleware, we just embed it directly.
+ ".indexOf('content-length') === -1) {", "}", () -> {
writer.write("const length = calculateBodyLength(body);");
writer.openBlock("if (length !== undefined) {", "}", () -> {
writer.write("headers = { ...headers, 'content-length': String(length) };");
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we reassign headers instead of mutating it?

Copy link
Contributor Author

@JordonPhillips JordonPhillips Jul 19, 2021

Choose a reason for hiding this comment

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

I based this off of what the client middleware plugin does. I'm not terribly attached to this approach though, so I can change it. @trivikr might have a stronger opinion

Copy link
Contributor

Choose a reason for hiding this comment

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

The reassigning was done to usable immutability. We'd discovered a bug in during pre-GA because of mutation, which was fixed by using destructuring assignment

@JordonPhillips JordonPhillips merged commit 851b17f into smithy-lang:main Jul 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants