Make WordPress Core


Ignore:
Timestamp:
10/27/2020 04:42:38 PM (4 years ago)
Author:
TimothyBlynJacobs
Message:

REST API: Support a broader range of JSON media types.

Previously, we only supported application/json which prevented using subtypes like application/activity+json. This allows for the REST API to json_decode the body of requests using a JSON subtype Content-Type. Additionally, wp_die() now properly sends the error as JSON when a JSON subtype is specified in the Accept header.

Props pfefferle.
Fixes #49404.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/functions.php

    r49027 r49329  
    17291729        );
    17301730    }
     1731
     1732    /**
     1733     * @ticket 49404
     1734     * @dataProvider data_test_wp_is_json_media_type
     1735     */
     1736    public function test_wp_is_json_media_type( $input, $expected ) {
     1737        $this->assertEquals( $expected, wp_is_json_media_type( $input ) );
     1738    }
     1739
     1740
     1741    public function data_test_wp_is_json_media_type() {
     1742        return array(
     1743            array( 'application/ld+json', true ),
     1744            array( 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', true ),
     1745            array( 'application/activity+json', true ),
     1746            array( 'application/json+oembed', true ),
     1747            array( 'application/json', true ),
     1748            array( 'application/nojson', false ),
     1749            array( 'application/no.json', false ),
     1750            array( 'text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, */*;q=0.8', false ),
     1751            array( 'application/activity+json, application/nojson', true ),
     1752        );
     1753    }
    17311754}
Note: See TracChangeset for help on using the changeset viewer.