From cc661013cfde2a79c71f28c5d94b1443cd11cbf3 Mon Sep 17 00:00:00 2001 From: Joe Hoyle Date: Sun, 7 May 2017 04:08:42 +0000 Subject: [PATCH] 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 --- src/wp-includes/rest-api/class-wp-rest-request.php | 1 + tests/phpunit/tests/rest-api/rest-request.php | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/src/wp-includes/rest-api/class-wp-rest-request.php b/src/wp-includes/rest-api/class-wp-rest-request.php index 74a81c92e8..0a26d0fe3d 100644 --- a/src/wp-includes/rest-api/class-wp-rest-request.php +++ b/src/wp-includes/rest-api/class-wp-rest-request.php @@ -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 ] ); } diff --git a/tests/phpunit/tests/rest-api/rest-request.php b/tests/phpunit/tests/rest-api/rest-request.php index ffd4ea29e7..db876bdb79 100644 --- a/tests/phpunit/tests/rest-api/rest-request.php +++ b/tests/phpunit/tests/rest-api/rest-request.php @@ -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';