reqwest icon indicating copy to clipboard operation
reqwest copied to clipboard

RequestBuilder::query and RequestBuilder::form both use application/x-www-form-urlencoded

Open dvaembit opened this issue 1 month ago • 0 comments

Both of these methods can be used to add parameters to the query string of the URL used in a GET request. They both encode the parameter using the application/x-www-form-urlencoded scheme.

However, I think one of these two statements is true:

  • The query method should not use the application/x-www-form-urlencoded scheme because it is only meant for forms. The URL percent-encoding should be used to encode spaces.
    • The WHATWG URL spec has this to say:

The application/x-www-form-urlencoded format is in many ways an aberrant monstrosity, the result of many years of implementation accidents and compromises leading to a set of requirements necessary for interoperability, but in no way representing good design practices. In particular, readers are cautioned to pay close attention to the twisted details involving repeated (and in some cases nested) conversions between character encodings and byte sequences. Unfortunately the format is in widespread use due to the prevalence of HTML forms. [HTML]

  • If the query method continues to use the application/x-www-form-urlencoded scheme then it should also clarify it's intent for the server by setting the content-type header.
    • However, then it essentially becomes the form method. So I suspect the prior point carries more weight.

dvaembit avatar Nov 24 '25 19:11 dvaembit