Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#54772 closed defect (bug) (reported-upstream)

Verify via wp_remote_get() if the website supports HTTP/2

Reported by: gabelivan's profile gabelivan Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: HTTP API Keywords:
Focuses: Cc:

Description

Hello, guys!

I want to use WordPress to verify whether a website (any URL I specify) has HTTP/2 support. It looks like I need to use custom PHP code with cURL instead of the WordPress functions. Here's an example:

<?PHP
$ch = curl_init();

$curlParams = array(
    CURLOPT_URL            => get_site_url(),
    CURLOPT_HEADER         => true,
    CURLOPT_NOBODY         => true,
    CURLOPT_RETURNTRANSFER => true
);

if (defined('CURLOPT_HTTP_VERSION') && defined('CURL_HTTP_VERSION_2_0')) {
   $curlParams[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_2_0;
}

curl_setopt_array($ch, $curlParams);

$response = curl_exec($ch);

if (! $response) {
   echo curl_error($ch);
}

if (strpos($response, 'HTTP/2') === 0) {
   $result['has_http2'] = '1'; // Has HTTP/2 Support
}

When checking /wp-includes/class-wp-http-curl.php, it looks like there's no way to add my own option and value to curl_setopt() via wp_remote_get(). The CURLOPT_HTTP_VERSION option is hardcoded like this:

<?php
if ( '1.0' === $parsed_args['httpversion'] ) {
    curl_setopt( $handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0 );
} else {
    curl_setopt( $handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1 );
}

Any ideas? I want to stick with the WordPress functions as much as possible instead of creating custom solutions.

Change History (4)

#1 @costdev
3 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed
  • Summary changed from Verufy via wp_remote_get() if the website supports HTTP/2 to Verify via wp_remote_get() if the website supports HTTP/2
  • Type changed from enhancement to defect (bug)

Hi @gabelivan and welcome to Trac!

Trac is for the development of WordPress Core, but you can get some help with your question from the folks over on the Advanced Support forums.

#2 @ocean90
3 years ago

  • Component changed from General to HTTP API
  • Resolution changed from invalid to reported-upstream

For HTTP requests WordPress uses the Requests library which has no HTTP/2 support yet. The related upstream issue is https://github.com/WordPress/Requests/issues/381.

Related: #53513

#3 @alanfuller
3 years ago

For the novice observer, what does 'reported-upstream' mean - I have no idea how complicated this is but at first glance it seems a simple 'fix' - how does a 'reported-upstream' get allocated to an issue for some one to run with?

#4 @costdev
3 years ago

Hi @alanfuller - I'm not sure how much you're already aware of, so I'm writing this as information in general.

WordPress relies on several other software projects. Sometimes an issue isn't in WordPress, but in one of these pieces of software. A project that WordPress relies on is upstream.

reported-upstream means that the issue has been reported to the software project where it applies/fits better and the team that work on that project will decide how they might proceed. Any changes made to the upstream project will be brought into WordPress if/when it's deemed appropriate.

The link that @ocean90 provided points to the issue on the Requests project, where the Requests team have marked it as an enhancement. Discussion should continue there to further the issue towards resolution.

Note: See TracTickets for help on using tickets.