[Rust][Reqwest] Utilise percent-encoding for path params when using reqwest

Merged
GL
1mo ago
+227-25

This PR fixes path parameter space encoding by modifying the urlencode fn to use percent-encoding in reqwest and reqwest-trait. They were originally sent as + as opposed to %20.

To more closely match previous behaviour, everything except unreserved characters is encoded, RFC3986 refers.

I've also added percent-encoding to Cargo.toml (incl. manually maintained ones), a codegen test and regenerated the samples.

Fixes #25257.

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.

@frol @farcaller @richardwhiuk @paladinzh @jacob-pro @dsteeley


Summary by cubic

Fixes a bug in the generated Rust reqwest and reqwest-trait clients where spaces in path parameters were encoded as + instead of %20, breaking URL paths with spaces.

  • Replaces the urlencode helper's form_urlencoded::byte_serialize implementation with percent_encoding::utf8_percent_encode, using a PATH_ENCODING_SET that percent-encodes all reserved characters per RFC3986 while keeping unreserved characters (-, ., _, ~) untouched. This preserves the previous encoding behavior for other reserved characters while fixing spaces.
  • Adds the percent-encoding dependency to generated Cargo.toml files, a codegen test covering both libraries, and regenerated samples.