[wp-trac] [WordPress Trac] #46992: Add a filter which allows the HTTP headers for REST API Endpoints to be changed

WordPress Trac noreply at wordpress.org
Tue Apr 23 03:44:37 UTC 2019


#46992: Add a filter which allows the HTTP headers for REST API Endpoints to be
changed
-------------------------+------------------------------
 Reporter:  sudar        |       Owner:  adamsilverstein
     Type:  enhancement  |      Status:  assigned
 Priority:  normal       |   Milestone:  5.3
Component:  REST API     |     Version:  trunk
 Severity:  normal       |  Resolution:
 Keywords:  has-patch    |     Focuses:
-------------------------+------------------------------

Comment (by sudar):

 @TimothyBlynJacobs

 The `rest_send_cors_headers` function uses the regular `header` php
 function to send the headers, but the headers that are sent are hardcoded
 in that function. There is no easy way to change the headers that will be
 passed to the `header` function.

 We have to remove the `rest_send_cors_headers` from the
 `rest_pre_serve_request` filter and then manually perform what is already
 done by `rest_send_cors_headers` function and then print the required
 headers.

 On the other hand if you want to change the headers for non rest pages,
 then all you have to do is hook into the `wp_headers` function and return
 the desired headers as array.

 This patch introduces a new filter, so that we can easily change the
 headers for rest api endpoints similar to how we do it for non rest api
 endpoints.

 Please let me know if my explanation is clear or if you still have any
 other questions.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/46992#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list