[php-src] Issue #22002: curl_setopt($ch,CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_2_0) does not honored when the CURLOPT_PROXY is combined

[email protected] (licaonkter)
Newsgroups php.bugs
Message-ID <[email protected]>
Issue: https://github.com/php/php-src/issues/22002
Author: licaonkter

### Description

The following code:

```php
<?php
set_time_limit(100);
function test1(){
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,'https://ftp.mozilla.org/');
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch,CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_2_0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HEADER,false);
curl_setopt($ch,CURLOPT_HTTPPROXYTUNNEL,true);
curl_setopt($ch,CURLOPT_PROXY,'127.0.0.1:8888');// SOCKS5H
curl_setopt($ch,CURLOPT_PROXYTYPE,CURLPROXY_SOCKS5_HOSTNAME);
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,http_build_query(['test'=>1]));
curl_setopt($ch,CURLOPT_HTTPHEADER,['Content-Type: application/x-www-form-urlencoded']);
curl_setopt($ch,CURLOPT_VERBOSE,true);
return curl_exec($ch);
}
function test2(){
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,'https://ftp.mozilla.org/');
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch,CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_2_0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HEADER,false);
// no proxy
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,http_build_query(['test'=>1]));
curl_setopt($ch,CURLOPT_HTTPHEADER,['Content-Type: application/x-www-form-urlencoded']);
curl_setopt($ch,CURLOPT_VERBOSE,true);
return curl_exec($ch);
}
var_dump(test1());
var_dump(test2());
```

Resulted in this output:
```
*   Trying 127.0.0.1:8888...
* SOCKS5 connect to ftp.mozilla.org:443 (remotely resolved)
* SOCKS5 request granted.
* Connected to 127.0.0.1 () port 8888
* using HTTP/1.x
* ALPN: curl offers h2,http/1.1
* ALPN: server accepted h2
* Server certificate:
...
* Connected to 127.0.0.1 (127.0.0.1) port 8888
* using HTTP/2
* [HTTP/2] [1] OPENED stream for https://ftp.mozilla.org/
...
> POST / HTTP/2
...
< HTTP/2 405

* Host ftp.mozilla.org:443 was resolved.
* ALPN: curl offers h2,http/1.1
* ALPN: server accepted h2
* Server certificate:
...
* Connected to ftp.mozilla.org () port 443
* using HTTP/2
* [HTTP/2] [1] OPENED stream for https://ftp.mozilla.org/
...
> POST / HTTP/2
...
< HTTP/2 405
```

But I expected:
- No `* using HTTP/1.x` in SOCKSified request; it should use HTTP2 from the beginning, just like without-proxy result

### PHP Version

```plain
PHP 8.4.16 (cli)
```

### Operating System

_No response_
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.