Changeset 35342
- Timestamp:
- 10/21/2015 08:37:56 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/rest-functions.php
r35324 r35342 255 255 } 256 256 257 if ( is_ssl() ) { 258 // If the current host is the same as the REST URL host, force the REST URL scheme to HTTPS 259 if ( $_SERVER['SERVER_NAME'] === parse_url( get_home_url( $blog_id ), PHP_URL_HOST ) ) { 260 $url = set_url_scheme( $url, 'https' ); 261 } 262 } 263 257 264 /** 258 265 * Filter the REST URL. -
trunk/tests/phpunit/tests/rest-api.php
r34928 r35342 252 252 // In non-pretty case, we get a query string to invoke the rest router. 253 253 $this->assertEquals( 'http://' . WP_TESTS_DOMAIN . '/?rest_route=/', get_rest_url() ); 254 } 254 255 } 256 257 /** 258 * @ticket 34299 259 */ 260 public function test_rest_url_scheme() { 261 if ( isset( $_SERVER['HTTPS'] ) ) { 262 $_https = $_SERVER['HTTPS']; 263 } 264 if ( isset( $_SERVER['SERVER_NAME'] ) ) { 265 $_name = $_SERVER['SERVER_NAME']; 266 } 267 $_SERVER['SERVER_NAME'] = parse_url( home_url(), PHP_URL_HOST ); 268 $_siteurl = get_option( 'siteurl' ); 269 270 // Test an HTTP URL 271 unset( $_SERVER['HTTPS'] ); 272 $url = get_rest_url(); 273 $this->assertSame( 'http', parse_url( $url, PHP_URL_SCHEME ) ); 274 275 // Test an HTTPS URL 276 $_SERVER['HTTPS'] = 'on'; 277 $url = get_rest_url(); 278 $this->assertSame( 'https', parse_url( $url, PHP_URL_SCHEME ) ); 279 280 // Switch to an admin request on a different domain name 281 $_SERVER['SERVER_NAME'] = 'admin.example.org'; 282 update_option( 'siteurl', 'http://admin.example.org' ); 283 $this->assertNotEquals( $_SERVER['SERVER_NAME'], parse_url( home_url(), PHP_URL_HOST ) ); 284 285 set_current_screen( 'edit.php' ); 286 $this->assertTrue( is_admin() ); 287 288 // Test an HTTP URL 289 unset( $_SERVER['HTTPS'] ); 290 $url = get_rest_url(); 291 $this->assertSame( 'http', parse_url( $url, PHP_URL_SCHEME ) ); 292 293 // Test an HTTPS URL 294 $_SERVER['HTTPS'] = 'on'; 295 $url = get_rest_url(); 296 $this->assertSame( 'http', parse_url( $url, PHP_URL_SCHEME ) ); 297 298 // Reset 299 if ( isset( $_https ) ) { 300 $_SERVER['HTTPS'] = $_https; 301 } else { 302 unset( $_SERVER['HTTPS'] ); 303 } 304 if ( isset( $_name ) ) { 305 $_SERVER['SERVER_NAME'] = $_name; 306 } else { 307 unset( $_SERVER['SERVER_NAME'] ); 308 } 309 update_option( 'siteurl', $_siteurl ); 310 set_current_screen( 'front' ); 311 312 } 313 255 314 }
Note: See TracChangeset
for help on using the changeset viewer.