JuliaWeb / HTTP.jl

HTTP for Julia
https://juliaweb.github.io/HTTP.jl/stable/
Other
626 stars 177 forks source link

Support decoding of `application/x-www-form-urlencoded` forms #1118

Open nguiard opened 9 months ago

nguiard commented 9 months ago

Hi! Thanks a lot for this library!

As HTTP.jl supports queryparams to decode parameters of a query string, I am surprised there's no facility to decode forms encoded in application/x-www-form-urlencoded. Especially as this is the default encoding for web forms.

Important to note is that the encoding is actually slightly different from query strings in URLs, so you can't just use queryparams as is on the body. The key difference is that a space character is encoded as a + in x-www-form-urlencoded while it is encoded as a %20 in URIs (https://developer.mozilla.org/en-US/docs/Glossary/percent-encoding).

While one can easily write a homegrown function in their project to take care of it, this body encoding is so ubiquitous that I suggest HTTP.jl should offer a standard function to decode it, and also an example in the documentation. Not doing so can also be error-prone for people not familiar with web forms: looking around a bit, they might think they can just use queryparams on the body, not realizing this is incorrect.

If you're fine with that, I can prepare a PR to add this functionality as well as a nice example of using it :)