WordPress.org

Make WordPress Core

Opened 8 weeks ago

Closed 3 weeks ago

#47005 closed defect (bug) (fixed)

check if SERVER_PROTOCOL is empty in load.php

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

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 weeks ago.

Download all attachments as: .zip

Change History (4)

@thakkarhardik
8 weeks ago

#1 @thakkarhardik
8 weeks 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 weeks ago

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

Previously: #21971

#3 @SergeyBiryukov
3 weeks ago

  • Resolution set to fixed
  • Status changed from reviewing to 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.