Merge branch 'Ayesh-curl/8-12/auth-used-consts'

* Ayesh-curl/8-12/auth-used-consts:
  ext/curl: Add `CURLINFO_{USED_PROXY,HTTPAUTH_USED,PROXYAUTH_USED}`
This commit is contained in:
Ayesh Karunaratne 2025-02-17 17:39:02 +07:00
commit d6b1d2e4ca
No known key found for this signature in database
7 changed files with 184 additions and 1 deletions

View file

@ -1000,6 +1000,18 @@ const CURLINFO_CAPATH = UNKNOWN;
*/
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 */
/**
@ -3054,6 +3066,13 @@ const CURLINFO_STARTTRANSFER_TIME_T = UNKNOWN;
* @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

View file

@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 7d3cd96f8725c59be46817487bb8d06e04384269 */
* Stub hash: 48fc95503f4f8cc96575ff6f31fdd1e4cdc5969e */
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_curl_close, 0, 1, IS_VOID, 0)
ZEND_ARG_OBJ_INFO(0, handle, CurlHandle, 0)
@ -429,6 +429,12 @@ static void register_curl_symbols(int module_number)
#endif
#if LIBCURL_VERSION_NUM >= 0x075400 /* Available since 7.84.0 */
REGISTER_LONG_CONSTANT("CURLINFO_CAINFO", CURLINFO_CAINFO, CONST_PERSISTENT);
#endif
#if LIBCURL_VERSION_NUM >= 0x080c00 /* Available since 8.12.0 */
REGISTER_LONG_CONSTANT("CURLINFO_HTTPAUTH_USED", CURLINFO_HTTPAUTH_USED, CONST_PERSISTENT);
#endif
#if LIBCURL_VERSION_NUM >= 0x080c00 /* Available since 8.12.0 */
REGISTER_LONG_CONSTANT("CURLINFO_PROXYAUTH_USED", CURLINFO_PROXYAUTH_USED, CONST_PERSISTENT);
#endif
REGISTER_LONG_CONSTANT("CURLMSG_DONE", CURLMSG_DONE, CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("CURLVERSION_NOW", CURLVERSION_NOW, CONST_PERSISTENT);
@ -811,6 +817,9 @@ static void register_curl_symbols(int module_number)
REGISTER_LONG_CONSTANT("CURLINFO_REDIRECT_TIME_T", CURLINFO_REDIRECT_TIME_T, CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("CURLINFO_STARTTRANSFER_TIME_T", CURLINFO_STARTTRANSFER_TIME_T, CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("CURLINFO_TOTAL_TIME_T", CURLINFO_TOTAL_TIME_T, CONST_PERSISTENT);
#if LIBCURL_VERSION_NUM >= 0x080700 /* Available since 8.7.0 */
REGISTER_LONG_CONSTANT("CURLINFO_USED_PROXY", CURLINFO_USED_PROXY, CONST_PERSISTENT);
#endif
#if LIBCURL_VERSION_NUM >= 0x080a00 /* Available since 8.10.0 */
REGISTER_LONG_CONSTANT("CURLINFO_POSTTRANSFER_TIME_T", CURLINFO_POSTTRANSFER_TIME_T, CONST_PERSISTENT);
#endif

View file

@ -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) {

View file

@ -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
}

View file

@ -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)

View file

@ -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)

View file

@ -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)