From f6eccf2fc1a629d408b8f40b6fc65b65870a5a50 Mon Sep 17 00:00:00 2001 From: Ayesh Karunaratne Date: Sun, 19 Jan 2025 11:32:20 +0700 Subject: [PATCH] ext/curl: Add `CURLINFO_{USED_PROXY,HTTPAUTH_USED,PROXYAUTH_USED}` Adds support for `curl_getinfo()` info keys and additional array keys: - [`CURLINFO_USED_PROXY`](https://curl.se/libcurl/c/CURLINFO_USED_PROXY.html) - `libcurl` >= 8.7.9 - Zero if no proxy was used in the previous transfer or a non-zero value if a proxy was used. - [`CURLINFO_HTTPAUTH_USED`](https://github.com/curl/curl/blob/curl-8_12_0/docs/libcurl/opts/CURLINFO_HTTPAUTH_USED.md) - `libcurl` >= 8.7.9 - Bitmask indicating the authentication method that was used in the previous HTTP request. - [`CURLINFO_PROXYAUTH_USED`](https://github.com/curl/curl/blob/curl-8_12_0/docs/libcurl/opts/CURLINFO_PROXYAUTH_USED.md) - `libcurl` >= 8.12.0 - Bitmask indicating the authentication method that was used in the previous request done over an HTTP proxy. ```php curl_getinfo($ch); ``` ```php [ // ... "used_proxy" => 0, "httpauth_used" => 0, "proxyauth_used" => 0, ] ``` Because the built-in server ext/curl tests use does not support HTTP authentication, there is an online test that uses httpbin. It will be skipped by default unless online tests are run. --- NEWS | 2 + UPGRADING | 17 +++++ ext/curl/curl.stub.php | 19 ++++++ ext/curl/curl_arginfo.h | 11 +++- ext/curl/interface.c | 13 ++++ ...getinfo_CURLINFO_HTTPAUTH_USED-online.phpt | 33 ++++++++++ .../curl_getinfo_CURLINFO_HTTPAUTH_USED.phpt | 66 +++++++++++++++++++ .../curl_getinfo_CURLINFO_USED_PROXY.phpt | 38 +++++++++++ 8 files changed, 198 insertions(+), 1 deletion(-) create mode 100644 ext/curl/tests/curl_getinfo_CURLINFO_HTTPAUTH_USED-online.phpt create mode 100644 ext/curl/tests/curl_getinfo_CURLINFO_HTTPAUTH_USED.phpt create mode 100644 ext/curl/tests/curl_getinfo_CURLINFO_USED_PROXY.phpt diff --git a/NEWS b/NEWS index 77c430e1ad845..20eb2849cb520 100644 --- a/NEWS +++ b/NEWS @@ -28,6 +28,8 @@ PHP NEWS - Curl: . Added curl_multi_get_handles(). (timwolla) . Added curl_share_init_persistent(). (enorris) + . Added CURLINFO_USED_PROXY, CURLINFO_HTTPAUTH_USED, and CURLINFO_PROXYAUTH_USED + support to curl_getinfo. (Ayesh Karunaratne) - Date: . Fix undefined behaviour problems regarding integer overflow in extreme edge diff --git a/UPGRADING b/UPGRADING index c8e4d45b7cae9..68f2a805e40c7 100644 --- a/UPGRADING +++ b/UPGRADING @@ -95,6 +95,18 @@ PHP 8.5 UPGRADE NOTES . Added support for share handles that are persisted across multiple PHP requests, safely allowing for more effective connection reuse. RFC: https://wiki.php.net/rfc/curl_share_persistence_improvement + . Added support for CURLINFO_USED_PROXY (libcurl >= 8.7.0), + CURLINFO_HTTPAUTH_USED, and CURLINFO_PROXYAUTH_USED + (libcurl >= 8.12.0) to the curl_getinfo() function. + When curl_getinfo() returns an array, the same information + is available as "used_proxy", "httpauth_used", and "proxyauth_used" + keys. + CURLINFO_USED_PROXY gets zero set if no proxy was used in the + previous transfer or a non-zero value if a proxy was used. + CURLINFO_HTTPAUTH_USED and CURLINFO_PROXYAUTH_USED get bitmasks + indicating the http and proxy authentication methods that were + used in the previous request. See CURLAUTH_* constants for + possible values. - DOM: . Added Dom\Element::$outerHTML. @@ -262,6 +274,11 @@ PHP 8.5 UPGRADE NOTES - Core: . PHP_BUILD_DATE. +- Curl: + . CURLINFO_USED_PROXY. + . CURLINFO_HTTPAUTH_USED. + . CURLINFO_PROXYAUTH_USED. + - POSIX: . POSIX_SC_OPEN_MAX. diff --git a/ext/curl/curl.stub.php b/ext/curl/curl.stub.php index 9eb8bd5b49e87..c9abe237339b5 100644 --- a/ext/curl/curl.stub.php +++ b/ext/curl/curl.stub.php @@ -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 */ /** @@ -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 diff --git a/ext/curl/curl_arginfo.h b/ext/curl/curl_arginfo.h index e873e9e9f3277..6a81d1e92c88f 100644 --- a/ext/curl/curl_arginfo.h +++ b/ext/curl/curl_arginfo.h @@ -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 diff --git a/ext/curl/interface.c b/ext/curl/interface.c index 690f2ccc609c9..311b2f7cc8a59 100644 --- a/ext/curl/interface.c +++ b/ext/curl/interface.c @@ -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) { diff --git a/ext/curl/tests/curl_getinfo_CURLINFO_HTTPAUTH_USED-online.phpt b/ext/curl/tests/curl_getinfo_CURLINFO_HTTPAUTH_USED-online.phpt new file mode 100644 index 0000000000000..bebb7d1b953f1 --- /dev/null +++ b/ext/curl/tests/curl_getinfo_CURLINFO_HTTPAUTH_USED-online.phpt @@ -0,0 +1,33 @@ +--TEST-- +curl_getinfo - CURLINFO_HTTPAUTH_USED - online test +--EXTENSIONS-- +curl +--SKIPIF-- += 8.12.0"); +if (getenv("SKIP_ONLINE_TESTS")) die('skip online test'); +?> +--FILE-- + +--EXPECT-- +bool(true) +bool(true) diff --git a/ext/curl/tests/curl_getinfo_CURLINFO_HTTPAUTH_USED.phpt b/ext/curl/tests/curl_getinfo_CURLINFO_HTTPAUTH_USED.phpt new file mode 100644 index 0000000000000..ea004d3dc9eb4 --- /dev/null +++ b/ext/curl/tests/curl_getinfo_CURLINFO_HTTPAUTH_USED.phpt @@ -0,0 +1,66 @@ +--TEST-- +curl_getinfo - CURLINFO_HTTPAUTH_USED +--EXTENSIONS-- +curl +--SKIPIF-- += 8.12.0"); +?> +--FILE-- + +--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) diff --git a/ext/curl/tests/curl_getinfo_CURLINFO_USED_PROXY.phpt b/ext/curl/tests/curl_getinfo_CURLINFO_USED_PROXY.phpt new file mode 100644 index 0000000000000..7020a70f5247d --- /dev/null +++ b/ext/curl/tests/curl_getinfo_CURLINFO_USED_PROXY.phpt @@ -0,0 +1,38 @@ +--TEST-- +curl_getinfo - CURLINFO_USED_PROXY +--EXTENSIONS-- +curl +--SKIPIF-- += 8.7.0"); +?> +--FILE-- + +--EXPECT-- +bool(true) +bool(true) +bool(true) +bool(true) +bool(true)