Skip to content

[azure-core][bug] wrong content-type in headers of multipart request when there is no file to send #39163

Open
@msyyc

Description

For typespec definition https://github.com/allenjzhang/typespec-e2e-demo/blob/75f5f9ad85acb4e46095058bd1033ba9fe9be0a3/todoApp/spec/main.tsp#L84, the property for file part is optional which means the payload for multipart may not contain file and azure-core shall still send it as multipart payload. However, current azure-core use files to judge whether the payload is for multipart which is not accurate. If files are empty, the content-type of default_headers is set to application/x-www-form-urlencoded which is wrong.

default_headers = self._set_body(
content=content,
data=data,
files=files,
json=json,
)

if files:
default_headers, self._files = set_multipart_body(files)
if data:
default_headers, self._data = set_urlencoded_body(data, has_files=bool(files))

Steps to repro:

  1. clone https://github.com/allenjzhang/typespec-e2e-demo.git
  2. step into the cloned repo and run npm install
  3. annotate this line then follow https://github.com/allenjzhang/typespec-e2e-demo/blob/main/todoApp/samples/python/README.md to run the sample and you can get error:

Image

Metadata

Assignees

No one assigned

    Labels

    Azure.CoreClientThis issue points to a problem in the data-plane of the library.bugThis issue requires a change to an existing behavior in the product in order to be resolved.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions