Make WordPress Core


Ignore:
Timestamp:
10/07/2015 02:34:58 AM (11 years ago)
Author:
wonderboymusic
Message:

Introduce wp_get_server_protocol() to DRY protocol parsing logic and make adding more protocols, like HTTP/2, easier.

Props johnbillion, wonderboymusic.
Fixes #34131.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/load.php

    r34828 r34894  
    77 * @package WordPress
    88 */
     9
     10/**
     11 * Return the HTTP protocol sent by the server.
     12 *
     13 * @since 4.4.0
     14 *
     15 * @return string The HTTP protocol. Default: HTTP/1.0.
     16 */
     17function wp_get_server_protocol() {
     18        $protocol = $_SERVER['SERVER_PROTOCOL'];
     19        if ( ! in_array( $protocol, array( 'HTTP/1.1', 'HTTP/2', 'HTTP/2.0' ) ) ) {
     20                $protocol = 'HTTP/1.0';
     21        }
     22        return $protocol;
     23}
    924
    1025/**
     
    113128                wp_load_translations_early();
    114129
    115                 $protocol = $_SERVER['SERVER_PROTOCOL'];
    116                 if ( 'HTTP/1.1' !== $protocol && 'HTTP/1.0' !== $protocol ) {
    117                         $protocol = 'HTTP/1.0';
    118                 }
     130                $protocol = wp_get_server_protocol();
    119131                header( sprintf( '%s 500 Internal Server Error', $protocol ), true, 500 );
    120132                header( 'Content-Type: text/html; charset=utf-8' );
     
    125137                wp_load_translations_early();
    126138
    127                 $protocol = $_SERVER['SERVER_PROTOCOL'];
    128                 if ( 'HTTP/1.1' !== $protocol && 'HTTP/1.0' !== $protocol ) {
    129                         $protocol = 'HTTP/1.0';
    130                 }
     139                $protocol = wp_get_server_protocol();
    131140                header( sprintf( '%s 500 Internal Server Error', $protocol ), true, 500 );
    132141                header( 'Content-Type: text/html; charset=utf-8' );
     
    183192        wp_load_translations_early();
    184193
    185         $protocol = $_SERVER["SERVER_PROTOCOL"];
    186         if ( 'HTTP/1.1' != $protocol && 'HTTP/1.0' != $protocol )
    187                 $protocol = 'HTTP/1.0';
     194        $protocol = wp_get_server_protocol();
    188195        header( "$protocol 503 Service Unavailable", true, 503 );
    189196        header( 'Content-Type: text/html; charset=utf-8' );
Note: See TracChangeset for help on using the changeset viewer.