Changeset 40805
- Timestamp:
- 05/19/2017 08:26:48 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/class-wp-rest-server.php
r40238 r40805 253 253 if ( $send_no_cache_headers ) { 254 254 foreach ( wp_get_nocache_headers() as $header => $header_value ) { 255 $this->send_header( $header, $header_value ); 255 if ( empty( $header_value ) ) { 256 $this->remove_header( $header ); 257 } else { 258 $this->send_header( $header, $header_value ); 259 } 256 260 } 257 261 } … … 1264 1268 1265 1269 /** 1270 * Removes an HTTP header from the current response. 1271 * 1272 * @since 4.8.0 1273 * @access public 1274 * 1275 * @param string $key Header key. 1276 */ 1277 public function remove_header( $key ) { 1278 if ( function_exists( 'header_remove' ) ) { 1279 // In PHP 5.3+ there is a way to remove an already set header. 1280 header_remove( $key ); 1281 } else { 1282 // In PHP 5.2, send an empty header, but only as a last resort to 1283 // override a header already sent. 1284 foreach ( headers_list() as $header ) { 1285 if ( 0 === stripos( $header, "$key:" ) ) { 1286 $this->send_header( $key, '' ); 1287 break; 1288 } 1289 } 1290 } 1291 } 1292 1293 /** 1266 1294 * Retrieves the raw request entity (body). 1267 1295 * -
trunk/tests/phpunit/includes/spy-rest-server.php
r39343 r40805 30 30 public function send_header( $header, $value ) { 31 31 $this->sent_headers[ $header ] = $value; 32 } 33 34 public function remove_header( $header ) { 35 unset( $this->sent_headers[ $header ] ); 32 36 } 33 37 -
trunk/tests/phpunit/tests/rest-api/rest-server.php
r40238 r40805 764 764 765 765 foreach ( wp_get_nocache_headers() as $header => $value ) { 766 if ( empty( $value ) ) { 767 continue; 768 } 769 766 770 $this->assertTrue( isset( $headers[ $header ] ), sprintf( 'Header %s is not present in the response.', $header ) ); 767 771 $this->assertEquals( $value, $headers[ $header ] ); 768 772 } 773 774 // Last-Modified should be unset as per #WP23021 775 $this->assertFalse( isset( $headers['Last-Modified'] ), 'Last-Modified should not be sent.' ); 769 776 } 770 777
Note: See TracChangeset
for help on using the changeset viewer.