Make WordPress Core

Changeset 49133


Ignore:
Timestamp:
10/12/2020 08:09:14 PM (4 years ago)
Author:
TimothyBlynJacobs
Message:

REST API: Add HTTP/1.0 emulation to wp.apiRequest().

This allows for making REST API calls with the PUT and DELETE HTTP methods that may be blocked or unsupported by some server configurations.

Props yakimun.
Fixes #43605.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/wp/api-request.js

    r47122 r49133  
    1010 *
    1111 * @since 4.9.0
     12 * @since 5.6.0 Added overriding of the "PUT" and "DELETE" methods with "POST".
    1213 * @output wp-includes/js/api-request.js
    1314 */
     
    2425        var url = options.url;
    2526        var path = options.path;
     27        var method = options.method;
    2628        var namespaceTrimmed, endpointTrimmed, apiRoot;
    2729        var headers, addNonceHeader, headerName;
     
    7779        }
    7880
     81        if ( typeof method === 'string' ) {
     82            method = method.toUpperCase();
     83
     84            if ( 'PUT' === method || 'DELETE' === method ) {
     85                headers = $.extend( {
     86                    'X-HTTP-Method-Override': method
     87                }, headers );
     88
     89                method = 'POST';
     90            }
     91        }
     92
    7993        // Do not mutate the original options object.
    8094        options = $.extend( {}, options, {
    8195            headers: headers,
    82             url: url
     96            url: url,
     97            method: method
    8398        } );
    8499
Note: See TracChangeset for help on using the changeset viewer.