Repository navigation
[azure-core] Fix wrong urlencoded content-type for multipart requests with empty files - #49701
Open
Karan Dhaodiyal (karandhaodiyal28-hash) wants to merge 2 commits into
Conversation
…iles Passing `files` explicitly means the payload is multipart, even when no file part is present, so the urlencoded content-type header must not be set in that case. The truthiness check on `files` made an empty `files` value fall into the urlencoded branch and stamp application/x-www-form-urlencoded on the request. Fixes Azure#39163
Karan Dhaodiyal (karandhaodiyal28-hash)
requested review from
iscai-msft,
Kashif Khan (kashifkhan) and
Jeff Fisher (xirzec)
as code owners
October 25, 2026 15:53
Contributor
|
Thank you for your contribution Karan Dhaodiyal (@karandhaodiyal28-hash)! We will review the pull request and get back to you soon. |
|
Azure Pipelines: Successfully started running 3 pipeline(s). 5 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Author
|
The remaining test failures look unrelated to this change — they're all in dependent packages, not azure-core itself: azure-mgmt-core's httpretty-mocked tests fail with ServiceResponseError: RemoteDisconnected from the socket-mock layer, and the identity/cosmos failures are likewise in their own suites. azure-core's own tests pass. Happy to re-run if useful. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Passing
filesexplicitly means the payload is multipart, even when no file part is present — for example Typespec-generated clients with an optional file property pass an emptyfiles. The truthiness check inHttpRequest._set_bodymade that case fall into the urlencoded branch, so the request got stamped withapplication/x-www-form-urlencoded:This mirrors the approach sketched by Yuchao Yan (@msyyc) in the issue: when
fileswas explicitly passed (even empty), the urlencoded content-type must not be set, so the transport decides the multipart encoding.set_multipart_bodyis still only called for non-emptyfiles, sorequest.filesstaysNonein the empty case and nothing changes for existing callers.If you'd rather have the explicit
is_multipart_payloadkwarg onHttpRequestas sketched in the issue, happy to add that instead.Adds a regression test next to the existing urlencoded content-type tests.
Fixes #39163