REST API: WP_REST_Request::remove_header() should canonicalize header names.

When headers are stored in WP_REST_Request internally they are canonicalized. This step already happens on setting / getting headers in any way, but was missed when implementing remove_header().

Props TimothyBlynJacobs.
Fixes #40347.


git-svn-id: https://develop.svn.wordpress.org/trunk@40577 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Joe Hoyle 2017-05-07 04:08:42 +00:00
parent 09fad66ae4
commit cc661013cf
2 changed files with 9 additions and 0 deletions

View File

@ -286,6 +286,7 @@ class WP_REST_Request implements ArrayAccess {
* @param string $key Header name.
*/
public function remove_header( $key ) {
$key = $this->canonicalize_header_name( $key );
unset( $this->headers[ $key ] );
}

View File

@ -30,6 +30,14 @@ class Tests_REST_Request extends WP_UnitTestCase {
$this->assertNull( $this->request->get_header( 'missing' ) );
$this->assertNull( $this->request->get_header_as_array( 'missing' ) );
}
public function test_remove_header() {
$this->request->add_header( 'Test-Header', 'value' );
$this->assertEquals( 'value', $this->request->get_header( 'Test-Header' ) );
$this->request->remove_header( 'Test-Header' );
$this->assertNull( $this->request->get_header( 'Test-Header' ) );
}
public function test_header_multiple() {
$value1 = 'application/x-wp-example-1';