Make WordPress Core

Opened 8 years ago

Closed 7 years ago

#47005 closed defect (bug) (fixed)

check if SERVER_PROTOCOL is empty in load.php

Reported by: malthert Owned by: SergeyBiryukov
Priority: normal Milestone: 5.3
Component: Bootstrap/Load Version: 5.2
Severity: normal Keywords: has-patch
Cc: Focuses:

Description

In php cli requests, the server_protocol may not be set, throwing a notice
This should be changed in /wp-includes/wp-load.php

function wp_get_server_protocol() {
	$protocol = $_SERVER['SERVER_PROTOCOL'];
	if ( ! in_array( $protocol, array( 'HTTP/1.1', 'HTTP/2', 'HTTP/2.0' ) ) ) {
		$protocol = 'HTTP/1.0';
	}
	return $protocol;
}

to this:

function wp_get_server_protocol() {
	$protocol = isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : '';
	if ( ! in_array( $protocol, array( 'HTTP/1.1', 'HTTP/2', 'HTTP/2.0' ), true ) ) {
		$protocol = 'HTTP/1.0';
	}
	return $protocol;
}

Attachments (1)

47005.patch​ (551 bytes ) - added by thakkarhardik 8 years ago.

Download all attachments as: .zip

Change History (4)

#1 @thakkarhardik
8 years ago

  • Keywords has-patch added; needs-patch removed

Yes @malthert , it did throw a warning. I have added a patch as per your suggestion.

#2 @SergeyBiryukov
8 years ago

  • Component General → Bootstrap/Load
  • Milestone Awaiting Review → 5.3
  • Owner set to SergeyBiryukov
  • Status new → reviewing

Previously: #21971

#3 @SergeyBiryukov
7 years ago

  • Resolution → fixed
  • Status reviewing → closed

In 45400:

Bootstrap/Load: In wp_get_server_protocol(), check if $_SERVER['SERVER_PROTOCOL'] is defined, to avoid a notice in CLI context.

Props thakkarhardik, malthert.
Fixes #47005.

Note: See TracTickets for help on using tickets.