WordPress.org

Make WordPress Core

Changeset 48112


Ignore:
Timestamp:
06/20/2020 11:54:32 PM (4 months ago)
Author:
TimothyBlynJacobs
Message:

REST API: Add "Link" to the list of exposed cors headers.

Currently, only the X-WP-Total and X-WP-TotalPages headers are exposed which means that clients have to manually construct the URL to implement pagination instead of using the "prev" and "next" Links.

Additionally, a filter "rest_exposed_cors_headers" is introduced to make it simpler for plugins to expose additional headers.

Props Toro_Unit, ayeshrajans.
Fixes #50369.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/class-wp-rest-server.php

    r47926 r48112  
    244244         */
    245245        $this->send_header( 'X-Content-Type-Options', 'nosniff' );
    246         $this->send_header( 'Access-Control-Expose-Headers', 'X-WP-Total, X-WP-TotalPages' );
     246        $expose_headers = array( 'X-WP-Total', 'X-WP-TotalPages', 'Link' );
     247
     248        /**
     249         * Filters the list of response headers that are exposed to CORS requests.
     250         *
     251         * @since 5.5.0
     252         *
     253         * @param string[] $expose_headers The list of headers to expose.
     254         */
     255        $expose_headers = apply_filters( 'rest_exposed_cors_headers', $expose_headers );
     256
     257        $this->send_header( 'Access-Control-Expose-Headers', implode( ', ', $expose_headers ) );
    247258        $this->send_header( 'Access-Control-Allow-Headers', 'Authorization, Content-Type' );
    248259
Note: See TracChangeset for help on using the changeset viewer.