[BUG][PYTHON] Account for content-type parameters on request preparation

Merged
MA
2mo ago
+120-25

PR checklist

  • Read the contribution guidelines.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

Fixes #23990. A description and a guide on how to reproduce the issue can be found there.

The proposed changes include a new helper function called contenttype_matches that returns true when a given content-type string matches the given type and subtype, otherwise it returns false. Mime type parameters are ignored, but can be optionally be present in the provided string. It also allows for vendor specifications. For example, application/vendor+json is also considered valid against type=application, subtype=json.

@cbornet @tomplus @krjakbrjak @fa0311 @multani


Summary by cubic

Fixes #23990 by making the Python client’s Content-Type matching robust during request prep. We now ignore parameters (including optional whitespace) and accept vendor-suffixed types so request bodies use the right encoder.

  • Bug Fixes
    • Added contenttype_matches helper (case-insensitive, ignores MIME parameters/whitespace, supports vendor+subtype) and documented it at module scope.
    • Switched detection for JSON, application/x-www-form-urlencoded, multipart/form-data, and YAML (application/yaml, text/yaml, text/x-yaml) to use the helper.
    • Use content_type for text/* boolean handling; updated Python template and regenerated samples.