Skip to content

Commit d23e36d

Browse files
Ayeshnikic
authored andcommitted
Add CURLINFO_EFFECTIVE_METHOD
Since Curl 7.72.0, it supports a new parameter called `CURLINFO_EFFECTIVE_METHOD`, which returns the effect method in HTTP(s) requests. This is similar to `CURLINFO_EFFECTIVE_URL`. - https://curl.se/libcurl/c/CURLINFO_EFFECTIVE_METHOD.html This adds support for CURLINFO_EFFECTIVE_URL if ext/curl is built with libcurl >= 7.72.0 (0x074800). Closes phpGH-7595.
1 parent b743cd7 commit d23e36d

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

UPGRADING

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ PHP 8.2 UPGRADE NOTES
2323
2. New Features
2424
========================================
2525

26+
- Curl:
27+
. Added CURLINFO_EFFECTIVE_METHOD option and returning the effective
28+
HTTP method in curl_getinfo() return value.
29+
2630
========================================
2731
3. Changes in SAPI modules
2832
========================================

ext/curl/interface.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,9 @@ PHP_MINIT_FUNCTION(curl)
552552
REGISTER_CURL_CONSTANT(CURLINFO_SSL_VERIFYRESULT);
553553
REGISTER_CURL_CONSTANT(CURLINFO_STARTTRANSFER_TIME);
554554
REGISTER_CURL_CONSTANT(CURLINFO_TOTAL_TIME);
555+
#if LIBCURL_VERSION_NUM >= 0x074800 /* Available since 7.72.0 */
556+
REGISTER_CURL_CONSTANT(CURLINFO_EFFECTIVE_METHOD);
557+
#endif
555558

556559
/* Other */
557560
REGISTER_CURL_CONSTANT(CURLMSG_DONE);
@@ -3257,6 +3260,11 @@ PHP_FUNCTION(curl_getinfo)
32573260
if (ch->header.str) {
32583261
CAASTR("request_header", ch->header.str);
32593262
}
3263+
#if LIBCURL_VERSION_NUM >= 0x074800 /* Available since 7.72.0 */
3264+
if (curl_easy_getinfo(ch->cp, CURLINFO_EFFECTIVE_METHOD, &s_code) == CURLE_OK) {
3265+
CAAS("effective_method", s_code);
3266+
}
3267+
#endif
32603268
} else {
32613269
switch (option) {
32623270
case CURLINFO_HEADER_OUT:

ext/curl/tests/curl_basic_025.phpt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
Test curl_getinfo() function with CURLINFO_* from curl >= 7.72.0
3+
--EXTENSIONS--
4+
curl
5+
--SKIPIF--
6+
<?php $curl_version = curl_version();
7+
if ($curl_version['version_number'] < 0x074800) {
8+
exit("skip: test works only with curl >= 7.72.0");
9+
}
10+
?>
11+
--FILE--
12+
<?php
13+
14+
include 'server.inc';
15+
16+
$ch = curl_init();
17+
$host = curl_cli_server_start();
18+
19+
$url = "{$host}/get.inc?test=";
20+
curl_setopt($ch, CURLOPT_URL, $url);
21+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
22+
curl_setopt($ch, CURLOPT_POSTFIELDS, "data");
23+
curl_exec($ch);
24+
var_dump(curl_getinfo($ch, CURLINFO_EFFECTIVE_METHOD));
25+
curl_close($ch);
26+
?>
27+
--EXPECT--
28+
string(4) "POST"

0 commit comments

Comments
 (0)