Skip to content

[python] multipart/form-data headers get URL-encoded via aiohttp.FormData #24376

Description

@luketudge

I have not specified [BUG] here because maybe this is still arguable, but I think something is wrong or at least missing.

This concerns how content disposition headers such as 'filename' on multipart/form-data payloads are handled inside the python asyncio client. These headers currently always get URL-encoded, which I think is not desirable or at least should be configurable. As far as I understand it, the specification does not require URL encoding for this content type (see for example https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Methods/POST and https://datatracker.ietf.org/doc/html/rfc7578#section-4.2), and users of the generated client might therefore pass in, for example, file names containing spaces or other non-URLable characters with the reasonable expectation that these arrive at the destination service as-is. But they don't.

Starting here the template handles application/x-www-form-urlencoded and multipart/form-data using aiohttp.FormData(). The default values on initializing this class unfortunately seem to mix some of the behavior appropriate to the form-urlencoded and form-data types, in particular defaulting to URL encoding for all fields, here. This has been noted as a problem before, for example in aio-libs/aiohttp#3910

In theory, there is a very simple change that would fix this, by changing the template here:

- data = aiohttp.FormData()
+ data = aiohttp.FormData(quote_fields=False)

However, I suppose there are likely to be users of openapi-generator out there who are relying on the (arguably incorrect) existing behavior, and this easier change would break their use. So this may need to be made configurable instead.

I am happy to make the simpler but possibly breaking change if that is acceptable, or to discuss how/whether this could be made an option or otherwise worked around.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions