diff --git a/wp-includes/rest-api/class-wp-rest-server.php b/wp-includes/rest-api/class-wp-rest-server.php index 9d4a5fec05..11b8897a2b 100644 --- a/wp-includes/rest-api/class-wp-rest-server.php +++ b/wp-includes/rest-api/class-wp-rest-server.php @@ -252,7 +252,11 @@ class WP_REST_Server { $send_no_cache_headers = apply_filters( 'rest_send_nocache_headers', is_user_logged_in() ); if ( $send_no_cache_headers ) { foreach ( wp_get_nocache_headers() as $header => $header_value ) { - $this->send_header( $header, $header_value ); + if ( empty( $header_value ) ) { + $this->remove_header( $header ); + } else { + $this->send_header( $header, $header_value ); + } } } @@ -1262,6 +1266,30 @@ class WP_REST_Server { } } + /** + * Removes an HTTP header from the current response. + * + * @since 4.8.0 + * @access public + * + * @param string $key Header key. + */ + public function remove_header( $key ) { + if ( function_exists( 'header_remove' ) ) { + // In PHP 5.3+ there is a way to remove an already set header. + header_remove( $key ); + } else { + // In PHP 5.2, send an empty header, but only as a last resort to + // override a header already sent. + foreach ( headers_list() as $header ) { + if ( 0 === stripos( $header, "$key:" ) ) { + $this->send_header( $key, '' ); + break; + } + } + } + } + /** * Retrieves the raw request entity (body). * diff --git a/wp-includes/version.php b/wp-includes/version.php index f710a38a5a..332dac6e32 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.8-beta1-40804'; +$wp_version = '4.8-beta1-40805'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.