Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ PHP 8.7 UPGRADE NOTES
rebuilding PHP with --enable-fd-setsize. On Windows, selecting on more than
64 pipe or file handles no longer crashes; it fails with a warning, as that
path remains bounded by WaitForMultipleObjects().
. The http stream wrapper now honors the "protocol_version" context option
for the CONNECT request sent to a proxy when tunneling HTTPS, and sends a
Host header in that case. Without the option, CONNECT still uses HTTP/1.0.

========================================
6. New Functions
Expand Down
13 changes: 12 additions & 1 deletion ext/standard/http_fopen_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,18 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,
smart_str_append(&header, resource->host);
smart_str_appendc(&header, ':');
smart_str_append_unsigned(&header, resource->port);
smart_str_appendl(&header, " HTTP/1.0\r\n", sizeof(" HTTP/1.0\r\n")-1);
if (context && (tmpzval = php_stream_context_get_option(context, "http", "protocol_version")) != NULL) {
smart_str_appends(&header, " HTTP/");
smart_str_append_printf(&header, "%.1F", zval_get_double(tmpzval));
/* HTTP/1.1 requires a Host header, which for CONNECT is the target authority */
smart_str_appends(&header, "\r\nHost: ");
smart_str_append(&header, resource->host);
smart_str_appendc(&header, ':');
smart_str_append_unsigned(&header, resource->port);
smart_str_appends(&header, "\r\n");
} else {
smart_str_appendl(&header, " HTTP/1.0\r\n", sizeof(" HTTP/1.0\r\n")-1);
}

/* check if we have Proxy-Authorization header */
if (context && (tmpzval = php_stream_context_get_option(context, "http", "header")) != NULL) {
Expand Down
45 changes: 45 additions & 0 deletions ext/standard/tests/http/http_proxy_ssl_connect_04.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
--TEST--
GH-8832 (HTTP proxy SSL CONNECT uses the http.protocol_version context option)
--EXTENSIONS--
openssl
--SKIPIF--
<?php require 'server.inc'; http_server_skipif(); ?>
--INI--
allow_url_fopen=1
--FILE--
<?php
require 'server.inc';

$responses = array(
"data://text/plain,HTTP/1.1 200 Connection established\r\n\r\n",
"data://text/plain,",
);

['pid' => $pid, 'uri' => $uri] = http_server($responses, $output);

$host = parse_url($uri, PHP_URL_HOST);
$port = parse_url($uri, PHP_URL_PORT);

$ctx = stream_context_create([
'http' => [
'proxy' => "tcp://$host:$port",
'protocol_version' => 1.1,
'header' => "Proxy-Authorization: Basic dXNlcjpwYXNz",
],
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
],
]);
@file_get_contents("https://www.php.net/test", false, $ctx);

http_server_kill($pid);

rewind($output);
$request = stream_get_contents($output);
var_dump(strstr($request, "\r\n\r\n", true));
?>
--EXPECT--
string(96) "CONNECT www.php.net:443 HTTP/1.1
Host: www.php.net:443
Proxy-Authorization: Basic dXNlcjpwYXNz"
Loading