php-src/ext
Ayesh Karunaratne ba748e7bb5
ext/curl: Add CURLOPT_DEBUGFUNCTION option (GH-15674)
This adds support for `CURLOPT_DEBUGFUNCTION`[^1] Curl option to set a
custom callback that gets called with debug information during the
lifetime of a Curl request.

The callback gets called with the `CurlHandle` object, an integer
containing the type of the debug message, and a string containing the
debug message. The callback may get called multiple times with the
same message type during a request.

PHP already uses `CURLOPT_DEBUGFUNCTION` functionality to internally
to expose a Curl option named `CURLINFO_HEADER_OUT`.

However,`CURLINFO_HEADER_OUT` is not a "real" Curl option supported
by libcurl. Back in 2006, `CURLINFO_HEADER_OUT` was added[^2] as
a Curl option by using the debug-callback feature. Git history does
not run that back to show why `CURLINFO_HEADER_OUT` was added as a
Curl option, and why the other debug types (such as
`CURLINFO_HEADER_IN` were not added as Curl options, but this seems
to be a historical artifact when we added features without trying
to be close to libcurl options.

This approach has a few issues:

1. `CURLINFO_HEADER_OUT` is not an actual Curl option supported by
  upstream libcurl.

2. All of the Curl options have `CURLOPT_` prefix, and `CURLINFO_HEADER_OUT`
  is the only Curl "option" that uses the `CURLINFO` prefix. This exception
  is, however, noted[^3] in docs.

3. When `CURLINFO_HEADER_OUT` is set, the `CURLOPT_VERBOSE` is also implicitly
  set. This was reported[^4] to bugs.php.net, but the bug is marked as wontfix.

This commit adds support for `CURLOPT_DEBUGFUNCTION`. It extends the existing
`curl_debug` callback to store the header-in information if it encounters
a debug message with `CURLINFO_HEADER_OUT`. In all cases, if a callable
is set, it gets called.

`CURLOPT_DEBUGFUNCTION` intends to replace `CURLINFO_HEADER_OUT` Curl
option as a versatile alternative that can also be used to extract
other debug information such as SSL data, text information messages,
incoming headers, as well as headers sent out (which `CURLINFO_HEADER_OUT`
makes available).

The callables are allowed to throw exceptions, but the return values are
ignored.

`CURLOPT_DEBUGFUNCTION` requires `CURLOPT_VERBOSE` enabled, and setting
`CURLOPT_DEBUGFUNCTION` does _not_ implicitly enable `CURLOPT_VERBOSE`.

If the `CURLOPT_DEBUGFUNCTION` option is set, setting `CURLINFO_HEADER_OUT`
throws a `ValueError` exception. Setting `CURLOPT_DEBUGFUNCTION` _after_
enabling `CURLINFO_HEADER_OUT` is allowed. Technically, it is possible
for both functionality (calling user-provided callback _and_ storing
header-out data) is possible, setting `CURLINFO_HEADER_OUT` is not
allowed to encourage the use of `CURLOPT_DEBUGFUNCTION` function.

This commit also adds the rest of the `CURLINFO_` constants used as
the `type` integer value in `CURLOPT_DEBUGFUNCTION` callback.

---

[^1]: [cur.se - CURLOPT_DEBUGFUNCTION](https://curl.se/libcurl/c/CURLOPT_DEBUGFUNCTION.html)
[^2]: [`5f25d80`](5f25d80d10)
[^3]: [curl_setopt doc mentioning `CURLINFO_` prefix is intentional](https://www.php.net/manual/en/function.curl-setopt.php#:~:text=prefix%20is%20intentional)
[^4]: [bugs.php.net - `CURLOPT_VERBOSE` does not work with `CURLINFO_HEADER_OUT`](https://bugs.php.net/bug.php?id=65348)
2024-09-24 10:56:56 +02:00
..
bcmath ext/bcmath: null should not be supported for operator overloading & fix some comparison issues (#15875) 2024-09-23 11:49:33 +01:00
bz2 Use "must not" instead of "cannot" wording 2024-08-21 21:12:17 +01:00
calendar Sync HAVE_<extension> help texts (#15167) 2024-08-02 01:41:47 +02:00
com_dotnet Generated arginfo header files: remove empty zend_function_entry arrays (#15705) 2024-09-03 23:19:53 +02:00
ctype Sync HAVE_<extension> help texts (#15167) 2024-08-02 01:41:47 +02:00
curl ext/curl: Add CURLOPT_DEBUGFUNCTION option (GH-15674) 2024-09-24 10:56:56 +02:00
date Merge branch 'PHP-8.3' 2024-09-14 22:15:49 +02:00
dba Generated arginfo header files: remove empty zend_function_entry arrays (#15705) 2024-09-03 23:19:53 +02:00
dl_test Autotools: Mark always-shared extensions with ext_shared variable (#15739) 2024-09-04 23:28:29 +02:00
dom [ci skip] Fix typo 2024-09-23 22:19:15 +02:00
enchant Rename ZEND_STR_DEPRECATED to ZEND_STR_DEPRECATED_CAPITALIZED (#15831) 2024-09-10 22:45:23 +01:00
exif Use "must not" instead of "cannot" wording 2024-08-21 21:12:17 +01:00
ffi Fix -Wundef/C4668 warnings (#15853) 2024-09-14 11:28:32 +02:00
fileinfo backporting GH-15755 fix. 2024-09-05 02:02:36 +01:00
filter Use "must not" instead of "cannot" wording 2024-08-21 21:12:17 +01:00
ftp Generated arginfo header files: remove empty zend_function_entry arrays (#15705) 2024-09-03 23:19:53 +02:00
gd Support building ext/gd without libxpm on Windows (GH-15846) 2024-09-12 12:29:18 +02:00
gettext Use "must not" instead of "cannot" wording 2024-08-21 21:12:17 +01:00
gmp ext/gmp: Use zend_result for type instead of int 2024-09-23 10:55:51 +01:00
hash Rename ZEND_STR_DEPRECATED to ZEND_STR_DEPRECATED_CAPITALIZED (#15831) 2024-09-10 22:45:23 +01:00
iconv Autotools: Fix iconv shared build with external library (#15686) 2024-09-01 22:06:37 +02:00
intl Rename ZEND_STR_DEPRECATED to ZEND_STR_DEPRECATED_CAPITALIZED (#15831) 2024-09-10 22:45:23 +01:00
json Generated arginfo header files: remove empty zend_function_entry arrays (#15705) 2024-09-03 23:19:53 +02:00
ldap Generated arginfo header files: combine preprocessor conditional blocks (#15736) 2024-09-04 13:04:22 +02:00
libxml Merge branch 'PHP-8.3' 2024-09-12 23:07:22 +02:00
mbstring ext/mbstring: Update to Unicode 16 2024-09-17 10:40:00 +09:00
mysqli Rename ZEND_STR_DEPRECATED to ZEND_STR_DEPRECATED_CAPITALIZED (#15831) 2024-09-10 22:45:23 +01:00
mysqlnd mysqlnd: support ER_CLIENT_INTERACTION_TIMEOUT (#13618) 2024-08-26 12:52:26 +09:00
odbc Rename ZEND_STR_DEPRECATED to ZEND_STR_DEPRECATED_CAPITALIZED (#15831) 2024-09-10 22:45:23 +01:00
opcache Fix GH-15972: Assertion failure in ext/opcache/jit/zend_jit_vm_helpers.c with function JIT (#16001) 2024-09-24 10:24:08 +03:00
openssl Support --with-openssl-argon2 on Windows (GH-15713) 2024-09-15 17:06:50 +02:00
pcntl Generated arginfo header files: combine preprocessor conditional blocks (#15736) 2024-09-04 13:04:22 +02:00
pcre Use APPLY_STOP in pcre_clean_cache() (GH-15839) 2024-09-12 22:32:23 +02:00
pdo Generated arginfo header files: remove empty zend_function_entry arrays (#15705) 2024-09-03 23:19:53 +02:00
pdo_dblib Add comments about internal headers (GH-15689) 2024-09-08 16:11:25 +02:00
pdo_firebird Add comments about internal headers (GH-15689) 2024-09-08 16:11:25 +02:00
pdo_mysql Add comments about internal headers (GH-15689) 2024-09-08 16:11:25 +02:00
pdo_odbc Add comments about internal headers (GH-15689) 2024-09-08 16:11:25 +02:00
pdo_pgsql Fix GH-15986: Double-free due to Pdo\Pgsql::setNoticeCallback() 2024-09-22 23:35:05 +02:00
pdo_sqlite Don't export php_pdo_int.h 2024-09-01 13:33:53 +02:00
pgsql Rename ZEND_STR_DEPRECATED to ZEND_STR_DEPRECATED_CAPITALIZED (#15831) 2024-09-10 22:45:23 +01:00
phar Merge branch 'PHP-8.3' 2024-09-24 02:24:02 -03:00
posix Use "must not" instead of "cannot" wording 2024-08-21 21:12:17 +01:00
random Rename ZEND_STR_DEPRECATED to ZEND_STR_DEPRECATED_CAPITALIZED (#15831) 2024-09-10 22:45:23 +01:00
readline Fix -Wundef/C4668 warnings (#15853) 2024-09-14 11:28:32 +02:00
reflection php_reflection.c: make a bunch of pointers const (#15927) 2024-09-17 03:17:46 +02:00
session Use php_error_docref() instead of zend_error() in session.c (GH-15505) 2024-09-04 16:00:28 +02:00
shmop Make ext/shmop/tests/gh14537.phpt more resilient (GH-15985) 2024-09-22 17:03:16 +02:00
simplexml Merge branch 'PHP-8.3' 2024-09-11 20:40:01 +02:00
skeleton Update skeleton extension .gitignore (#15738) 2024-09-05 07:14:29 +02:00
snmp Support bug64159.phpt on Windows CI (GH-15895) 2024-09-21 16:03:25 +02:00
soap Merge branch 'PHP-8.3' 2024-09-16 20:51:34 +02:00
sockets Generated arginfo header files: combine preprocessor conditional blocks (#15736) 2024-09-04 13:04:22 +02:00
sodium Generated arginfo header files: combine preprocessor conditional blocks (#15736) 2024-09-04 13:04:22 +02:00
spl zend_assert_valid_class_name(): use double quotes around names (#15990) 2024-09-23 00:44:16 +01:00
sqlite3 Generated arginfo header files: remove empty zend_function_entry arrays (#15705) 2024-09-03 23:19:53 +02:00
standard Inlines the behaviour of php_mkdir_ex() into plain wrapper mkdir handler (#15520) 2024-09-23 00:40:02 +01:00
sysvmsg Generated arginfo header files: remove empty zend_function_entry arrays (#15705) 2024-09-03 23:19:53 +02:00
sysvsem Generated arginfo header files: remove empty zend_function_entry arrays (#15705) 2024-09-03 23:19:53 +02:00
sysvshm Generated arginfo header files: remove empty zend_function_entry arrays (#15705) 2024-09-03 23:19:53 +02:00
tidy Autotools: Fix tidy library checks (#15576) 2024-08-27 00:00:20 +02:00
tokenizer [RFC] Asymmetric visibility v2 (GH-15063) 2024-08-27 02:04:48 +02:00
xml Merge branch 'PHP-8.3' 2024-09-13 20:02:00 +02:00
xmlreader Fix -Wundef/C4668 warnings (#15853) 2024-09-14 11:28:32 +02:00
xmlwriter Fix registration of internal readonly child classes (#15459) 2024-08-24 12:36:54 +02:00
xsl Fix registration of internal readonly child classes (#15459) 2024-08-24 12:36:54 +02:00
zend_test Merge branch 'PHP-8.3' 2024-09-12 23:11:28 +02:00
zip add ZipArchive::ER_TRUNCATED_ZIP added in libzip 1.11 (#15959) 2024-09-19 15:32:55 +02:00
zlib Remove Travis artefacts (#15714) 2024-09-04 01:15:10 +02:00
ext_skel.php