Skip to content

Conversation

@dicej
Copy link
Collaborator

@dicej dicej commented Sep 16, 2024

Previously, the spin_sdk.http.send function automatically added a content-length header to the header dictionary supplied by the caller if one was not already present and if a request body was specified. However, since we were mutating the dictionary in-place, the change was visible to the caller. In addition to being potentially surprising to the caller, that can lead to issues if the same object is reused for another request later, at which point the header we added earlier will still be present but not necessarily accurate for the new request.

To avoid such confusion, we now make a copy and add the content-length header to the copy.

Previously, the `spin_sdk.http.send` function automatically added a
`content-length` header to the header dictionary supplied by the caller if one
was not already present and if a request body was specified.  However, since we
were mutating the dictionary in-place, the change was visible to the caller.  In
addition to being potentially surprising to the caller, that can lead to issues
if the same object is reused for another request later, at which point the
header we added earlier will still be present but not necessarily accurate for
the new request.

To avoid such confusion, we now make a copy and add the `content-length` header
to the copy.

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
@dicej dicej requested a review from karthik2804 September 16, 2024 21:22
@dicej dicej merged commit b7e9caf into spinframework:main Sep 23, 2024
@dicej dicej deleted the no-in-place-header-mutation branch September 23, 2024 17:17
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.

2 participants