Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Send POST requests using FormData if possible
This partially walks back f6e28b5. It turns out that the type of the fetch body affects the Content-Type sent with the request: URLSearchParams corresponds to application/x-www-form-urlencoded and FormData to multipart/form-data. For a simple request, the former looks like this: Content-Type: application/x-www-form-urlencoded;charset=UTF-8 meta=siteinfo&format=json Whereas the latter looks like this: Content-Type: multipart/form-data; boundary=---------------------------384998708438653208232613793789 -----------------------------384998708438653208232613793789 Content-Disposition: form-data; name="meta" siteinfo -----------------------------384998708438653208232613793789 Content-Disposition: form-data; name="format" json -----------------------------384998708438653208232613793789-- So using URLSearchParams is already much more efficient, resulting in fewer bytes being sent over the wire (though in most m3api applications the majority of traffic will be received from the server anyway; and note that this only applies to POST requests anyway, not GET requests). Additionally, it turns out that OAuth 2.0 requires requests to the access token endpoint to be sent using application/x-www-form-urlencoded (according to section 4.1.3 of RFC 6749 [1]), and recently MediaWiki started to enforce this [2], which meant that m3api-oauth2 was broken for Wikimedia production with all m3api versions since 0.8.0. Using URLSearchParams when possible fixes lucaswerkmeister/m3api-oauth2/#3. [1]: https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.3 [2]: https://gerrit.wikimedia.org/r/c/mediawiki/extensions/OAuth/+/1046715
- Loading branch information
8e7e4c2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, make that lucaswerkmeister/m3api-oauth2#3.