WordPress / wordpress-playground

Run WordPress in the browser via WebAssembly PHP
https://w.org/playground/
GNU General Public License v2.0
1.65k stars 263 forks source link

Networking: Preserve the content-type header when fetch()-ing #2028

Closed adamziel closed 3 days ago

adamziel commented 4 days ago

Allows the use of arbitrary Content-type header when sending POST requests from WordPress.

Playground fetch() network transport for wp_safe_remote_* calls enforced the Content-Type header of application/x-www-form-urlencoding when POST-ing. This PR turns that value into a fallback that's only used if not explicit value is provided.

Closes https://github.com/WordPress/wordpress-playground/issues/1428

Testing instructions

http://localhost:5400/website-server/#{%22features%22:{%22networking%22:true},%22steps%22:[{%22step%22:%22writeFile%22,%22path%22:%22/wordpress/wp-content/mu-plugins/0-fetch-test.php%22,%22data%22:%22%3C?php%20add_action('init',%20function()%20{%20wp_safe_remote_post('https://api.w.org',array('headers'=%3E['Content-Type'=%3E'text/plain']));%20});%20%22}]}