Skip to content

Commit ad65698

Browse files
committed
ext/curl: CURLOPT_FOLLOWLOCATION option handling.
it had been considered as boolean for years but since 8.13, it can accept values beyond 1L, respectively CURLFOLLOW_OBEYCODE and CURLFOLLOW_FIRSTONLY. close GH-18444
1 parent 82e09db commit ad65698

File tree

6 files changed

+84
-6
lines changed

6 files changed

+84
-6
lines changed

NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ PHP NEWS
1515
. Fixed GH-17956 - development server 404 page does not adapt to mobiles.
1616
(pascalchevrel)
1717

18+
- CURL:
19+
. Added CURLFOLLOW_ALL, CURLFOLLOW_OBEYCODE and CURLFOLLOW_FIRSTONLY
20+
values for CURLOPT_FOLLOLOCATION curl_easy_setopt option. (David Carlier)
21+
1822
- COM:
1923
. Fixed property access of PHP objects wrapped in variant. (cmb)
2024
. Fixed method calls for PHP objects wrapped in variant. (cmb)

UPGRADING

+15
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,13 @@ PHP 8.5 UPGRADE NOTES
159159
CURLOPT_INFILESIZE only accepts a 32-bit signed integer as the file
160160
size (2.0 GiB) even on 64-bit systems. CURLOPT_INFILESIZE_LARGE
161161
accepts the largest integer value the system can handle.
162+
. Added CURLFOLLOW_OBEYCODE, CURLFOLLOW_FIRSTONLY and CURLFOLLOW_ALL values for
163+
CURLOPT_FOLLOWLOCATION curl_easy_setopt option.
164+
CURLFOLLOW_OBEYCODE to follow more strictly in regard of redirect
165+
if they are allowed. CURLFOLLOW_FIRSTONLY to follow only the
166+
first redirect thus if there any follow up redirect, it won't go
167+
any further. CURLFOLLOW_ALL is equivalent to set CURLOPT_FOLLOWLOCATION
168+
to true.
162169

163170
- DOM:
164171
. Added Dom\Element::$outerHTML.
@@ -361,6 +368,11 @@ PHP 8.5 UPGRADE NOTES
361368
9. Other Changes to Extensions
362369
========================================
363370

371+
- Curl:
372+
. curl_easy_setopt with CURLOPT_FOLLOWLOCATION option's value no longer
373+
is treated as boolean but integer to handle CURLFOLLOW_OBEYCODE and
374+
CURLFOLLOW_FIRSTONLY.
375+
364376
- Fileinfo:
365377
. Upgraded to file 5.46.
366378
. The return type of finfo_close() has been changed to true, rather
@@ -387,6 +399,9 @@ PHP 8.5 UPGRADE NOTES
387399
. CURLINFO_HTTPAUTH_USED.
388400
. CURLINFO_PROXYAUTH_USED.
389401
. CURLOPT_INFILESIZE_LARGE.
402+
. CURLFOLLOW_ALL.
403+
. CURLFOLLOW_OBEYCODE.
404+
. CURLFOLLOW_FIRSTONLY.
390405

391406
- Intl:
392407
. DECIMAL_COMPACT_SHORT.

ext/curl/curl.stub.php

+18
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,24 @@
497497
*/
498498
const CURLOPT_DEBUGFUNCTION = UNKNOWN;
499499

500+
#if LIBCURL_VERSION_NUM >= 0x080d00 /* Available since 8.13.0 */
501+
/**
502+
* @var int
503+
* @cvalue CURLFOLLOW_ALL
504+
*/
505+
const CURLFOLLOW_ALL = UNKNOWN;
506+
/**
507+
* @var int
508+
* @cvalue CURLFOLLOW_OBEYCODE
509+
*/
510+
const CURLFOLLOW_OBEYCODE = UNKNOWN;
511+
/**
512+
* @var int
513+
* @cvalue CURLFOLLOW_FIRSTONLY
514+
*/
515+
const CURLFOLLOW_FIRSTONLY = UNKNOWN;
516+
#endif
517+
500518
/**
501519
* @var int
502520
* @cvalue CURLINFO_TEXT

ext/curl/curl_arginfo.h

+10-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/curl/interface.c

+1-5
Original file line numberDiff line numberDiff line change
@@ -1863,6 +1863,7 @@ static zend_result _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue
18631863
#if LIBCURL_VERSION_NUM >= 0x080900 /* Available since 8.9.0 */
18641864
case CURLOPT_TCP_KEEPCNT:
18651865
#endif
1866+
case CURLOPT_FOLLOWLOCATION:
18661867
lval = zval_get_long(zvalue);
18671868
if ((option == CURLOPT_PROTOCOLS || option == CURLOPT_REDIR_PROTOCOLS) &&
18681869
(PG(open_basedir) && *PG(open_basedir)) && (lval & CURLPROTO_FILE)) {
@@ -2210,11 +2211,6 @@ static zend_result _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue
22102211
/* Do nothing, just backward compatibility */
22112212
break;
22122213

2213-
case CURLOPT_FOLLOWLOCATION:
2214-
lval = zend_is_true(zvalue);
2215-
error = curl_easy_setopt(ch->cp, option, lval);
2216-
break;
2217-
22182214
case CURLOPT_POSTFIELDS:
22192215
if (Z_TYPE_P(zvalue) == IS_ARRAY) {
22202216
if (zend_hash_num_elements(Z_ARRVAL_P(zvalue)) == 0) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
CURLOPT_FOLLOWLOCATION values
3+
--EXTENSIONS--
4+
curl
5+
--SKIPIF--
6+
<?php
7+
include 'skipif-nocaddy.inc';
8+
if (curl_version()['version_number'] < 0x080d00) die('skip requires curl >= 8.13.0');
9+
?>
10+
--FILE--
11+
<?php
12+
13+
foreach ([
14+
0,
15+
CURLFOLLOW_ALL,
16+
CURLFOLLOW_OBEYCODE,
17+
CURLFOLLOW_FIRSTONLY
18+
] as $follow) {
19+
$ch = curl_init();
20+
curl_setopt($ch,CURLOPT_URL, "https://localhost/redirect");
21+
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
22+
var_dump(curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $follow));
23+
var_dump(curl_exec($ch));
24+
curl_close($ch);
25+
}
26+
?>
27+
--EXPECTF--
28+
bool(true)
29+
string(%d) "%s"
30+
bool(true)
31+
string(%d) "%s"
32+
bool(true)
33+
string(%d) "%s"
34+
bool(true)
35+
string(%d) "%s"
36+

0 commit comments

Comments
 (0)