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';