Skip to content

ext/curl: Add CURLINFO_{USED_PROXY,HTTPAUTH_USED,PROXYAUTH_USED} #17816

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 17, 2025
Merged
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
19 changes: 19 additions & 0 deletions ext/curl/curl.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,18 @@
*/
const CURLINFO_CAINFO = UNKNOWN;
#endif
#if LIBCURL_VERSION_NUM >= 0x080c00 /* Available since 8.12.0 */
/**
* @var int
* @cvalue CURLINFO_HTTPAUTH_USED
*/
const CURLINFO_HTTPAUTH_USED = UNKNOWN;
/**
* @var int
* @cvalue CURLINFO_PROXYAUTH_USED
*/
const CURLINFO_PROXYAUTH_USED = UNKNOWN;
#endif

/* Other */
/**
Expand Down Expand Up @@ -3054,6 +3066,13 @@
* @cvalue CURLINFO_TOTAL_TIME_T
*/
const CURLINFO_TOTAL_TIME_T = UNKNOWN;
#if LIBCURL_VERSION_NUM >= 0x080700 /* Available since 8.7.0 */
/**
* @var int
* @cvalue CURLINFO_USED_PROXY
*/
const CURLINFO_USED_PROXY = UNKNOWN;
#endif
#if LIBCURL_VERSION_NUM >= 0x080a00 /* Available since 8.10.0 */
/**
* @var int
Expand Down
11 changes: 10 additions & 1 deletion ext/curl/curl_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions ext/curl/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -2662,6 +2662,19 @@ PHP_FUNCTION(curl_getinfo)
if (curl_easy_getinfo(ch->cp, CURLINFO_CAINFO, &s_code) == CURLE_OK) {
CAAS("cainfo", s_code);
}
#endif
#if LIBCURL_VERSION_NUM >= 0x080700 /* Available since 8.7.0 */
if (curl_easy_getinfo(ch->cp, CURLINFO_USED_PROXY, &l_code) == CURLE_OK) {
CAAL("used_proxy", l_code);
}
#endif
#if LIBCURL_VERSION_NUM >= 0x080c00 /* Available since 8.12.0 */
if (curl_easy_getinfo(ch->cp, CURLINFO_HTTPAUTH_USED, &l_code) == CURLE_OK) {
CAAL("httpauth_used", l_code);
}
if (curl_easy_getinfo(ch->cp, CURLINFO_PROXYAUTH_USED, &l_code) == CURLE_OK) {
CAAL("proxyauth_used", l_code);
}
#endif
} else {
switch (option) {
Expand Down
5 changes: 5 additions & 0 deletions ext/curl/tests/Caddyfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ respond / "Caddy is up and running"
respond /serverpush "main response"
respond /serverpush/pushed "pushed response"
push /serverpush /serverpush/pushed

basicauth /http-basic-auth {
# bcrypt password hash for "password", calculated with 'caddy hash-password'
user $2a$14$yUKl9SGqVTAAqPTzLup.DefsbXXx3kfreNnzpJOUHcIrKnr5lgef2
}
33 changes: 33 additions & 0 deletions ext/curl/tests/curl_getinfo_CURLINFO_HTTPAUTH_USED-caddy.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
--TEST--
curl_getinfo - CURLINFO_HTTPAUTH_USED - online test
--EXTENSIONS--
curl
--SKIPIF--
<?php
$curl_version = curl_version();
if ($curl_version['version_number'] < 0x080c00) die("skip: test works only with curl >= 8.12.0");
include 'skipif-nocaddy.inc';
?>
--FILE--
<?php

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://localhost/http-basic-auth");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$info = curl_getinfo($ch);
var_dump($info['httpauth_used'] === 0); // this is always 0 before executing the transfer

curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC | CURLAUTH_DIGEST);
curl_setopt($ch, CURLOPT_USERNAME, "foo");
curl_setopt($ch, CURLOPT_PASSWORD, "bar");

$result = curl_exec($ch);
$info = curl_getinfo($ch);

var_dump($info['httpauth_used'] === CURLAUTH_BASIC);

?>
--EXPECT--
bool(true)
bool(true)
66 changes: 66 additions & 0 deletions ext/curl/tests/curl_getinfo_CURLINFO_HTTPAUTH_USED.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
--TEST--
curl_getinfo - CURLINFO_HTTPAUTH_USED
--EXTENSIONS--
curl
--SKIPIF--
<?php
$curl_version = curl_version();
if ($curl_version['version_number'] < 0x080c00) die("skip: test works only with curl >= 8.12.0");
?>
--FILE--
<?php
include 'server.inc';

$host = curl_cli_server_start();
$port = (int) (explode(':', $host))[1];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "{$host}/get.inc?test=file");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

echo "httpauth_used and proxyauth_used empty\n";

$info = curl_getinfo($ch);
var_dump(isset($info['httpauth_used']));
var_dump(isset($info['proxyauth_used']));
var_dump($info['httpauth_used'] === 0); // this is always 0 before executing the transfer
var_dump($info['proxyauth_used'] === 0); // this is always 0 before executing the transfer

$result = curl_exec($ch);
echo "httpauth_used and proxyauth_used empty after request\n";
$info = curl_getinfo($ch);
var_dump(isset($info['httpauth_used']));
var_dump(isset($info['proxyauth_used']));
var_dump($info['httpauth_used'] === 0);
var_dump($info['proxyauth_used'] === 0);
var_dump(curl_getinfo($ch, CURLINFO_HTTPAUTH_USED) === $info['used_proxy']);
var_dump(curl_getinfo($ch, CURLINFO_PROXYAUTH_USED) === $info['proxyauth_used']);

echo "httpauth_used set after request\n";

$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC | CURLAUTH_DIGEST);
curl_setopt($ch, CURLOPT_USERNAME, "foo");
curl_setopt($ch, CURLOPT_PASSWORD, "bar");

$result = curl_exec($ch);
$info = curl_getinfo($ch);

var_dump($info['httpauth_used']); // Built-in server does not support auth

?>
--EXPECT--
httpauth_used and proxyauth_used empty
bool(true)
bool(true)
bool(true)
bool(true)
httpauth_used and proxyauth_used empty after request
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
httpauth_used set after request
int(0)
38 changes: 38 additions & 0 deletions ext/curl/tests/curl_getinfo_CURLINFO_USED_PROXY.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
--TEST--
curl_getinfo - CURLINFO_USED_PROXY
--EXTENSIONS--
curl
--SKIPIF--
<?php
$curl_version = curl_version();
if ($curl_version['version_number'] < 0x080700) die("skip: test works only with curl >= 8.7.0");
?>
--FILE--
<?php
include 'server.inc';

$host = curl_cli_server_start();
$port = (int) (explode(':', $host))[1];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "{$host}/get.inc?test=file");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$info = curl_getinfo($ch);
var_dump(isset($info['used_proxy']));
var_dump($info['used_proxy'] === 0); // this is always 0 before executing the transfer

$result = curl_exec($ch);

$info = curl_getinfo($ch);
var_dump(isset($info['used_proxy']));
var_dump($info['used_proxy'] === 0);
var_dump(curl_getinfo($ch, CURLINFO_USED_PROXY) === $info['used_proxy']);

?>
--EXPECT--
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
Loading