fermyon / spin-python-sdk

Spin SDK for Python
https://developer.fermyon.com/spin/v2/python-components
Apache License 2.0
31 stars 11 forks source link

avoid mutating request headers in-place #113

Closed dicej closed 1 month ago

dicej commented 1 month ago

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.