[wp-trac] [WordPress Trac] #54772: Verufy via wp_remote_get() if the website supports HTTP/2

WordPress Trac noreply at wordpress.org
Sun Jan 9 20:03:21 UTC 2022


#54772: Verufy via wp_remote_get() if the website supports HTTP/2
-------------------------+-----------------------------
 Reporter:  gabelivan    |      Owner:  (none)
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  General      |    Version:
 Severity:  normal       |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 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
 <?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
 <?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.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/54772>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list