Skip to content

ext/curl: CURLOPT_FOLLOWLOCATION option handling. #18444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@ PHP 8.5 UPGRADE NOTES
CURLOPT_INFILESIZE only accepts a 32-bit signed integer as the file
size (2.0 GiB) even on 64-bit systems. CURLOPT_INFILESIZE_LARGE
accepts the largest integer value the system can handle.
. Added CURLFOLLOW_OBEYCODE, CURLFOLLOW_FIRSTONLY and CURLFOLLOW_ALL values for
CURLOPT_FOLLOWLOCATION curl_easy_setopt option.
CURLFOLLOW_OBEYCODE to follow more strictly in regard of redirect
if they are allowed. CURLFOLLOW_FIRSTONLY to follow only the
first redirect thus if there any follow up redirect, it won't go
any further. CURLFOLLOW_ALL is equivalent to set CURLOPT_FOLLOWLOCATION
to true.

- DOM:
. Added Dom\Element::$outerHTML.
Expand Down Expand Up @@ -351,6 +358,11 @@ PHP 8.5 UPGRADE NOTES
9. Other Changes to Extensions
========================================

- Curl:
. curl_easy_setopt with CURLOPT_FOLLOWLOCATION option's value no longer
is treated as boolean but integer to handle CURLFOLLOW_OBEYCODE and
CURLFOLLOW_FIRSTONLY.

- Fileinfo:
. Upgraded to file 5.46.
. The return type of finfo_close() has been changed to true, rather
Expand All @@ -377,6 +389,9 @@ PHP 8.5 UPGRADE NOTES
. CURLINFO_HTTPAUTH_USED.
. CURLINFO_PROXYAUTH_USED.
. CURLOPT_INFILESIZE_LARGE.
. CURLFOLLOW_ALL.
. CURLFOLLOW_OBEYCODE.
. CURLFOLLOW_FIRSTONLY.

- Intl:
. DECIMAL_COMPACT_SHORT.
Expand Down
18 changes: 18 additions & 0 deletions ext/curl/curl.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,24 @@
*/
const CURLOPT_DEBUGFUNCTION = UNKNOWN;

#if LIBCURL_VERSION_NUM >= 0x080d00 /* Available since 8.13.0 */
/**
* @var int
* @cvalue CURLFOLLOW_ALL
*/
const CURLFOLLOW_ALL = UNKNOWN;
/**
* @var int
* @cvalue CURLFOLLOW_OBEYCODE
*/
const CURLFOLLOW_OBEYCODE = UNKNOWN;
/**
* @var int
* @cvalue CURLFOLLOW_FIRSTONLY
*/
const CURLFOLLOW_FIRSTONLY = UNKNOWN;
#endif

/**
* @var int
* @cvalue CURLINFO_TEXT
Expand Down
11 changes: 10 additions & 1 deletion ext/curl/curl_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions ext/curl/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -1863,6 +1863,7 @@ static zend_result _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue
#if LIBCURL_VERSION_NUM >= 0x080900 /* Available since 8.9.0 */
case CURLOPT_TCP_KEEPCNT:
#endif
case CURLOPT_FOLLOWLOCATION:
lval = zval_get_long(zvalue);
if ((option == CURLOPT_PROTOCOLS || option == CURLOPT_REDIR_PROTOCOLS) &&
(PG(open_basedir) && *PG(open_basedir)) && (lval & CURLPROTO_FILE)) {
Expand Down Expand Up @@ -2210,11 +2211,6 @@ static zend_result _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue
/* Do nothing, just backward compatibility */
break;

case CURLOPT_FOLLOWLOCATION:
lval = zend_is_true(zvalue);
error = curl_easy_setopt(ch->cp, option, lval);
break;

case CURLOPT_POSTFIELDS:
if (Z_TYPE_P(zvalue) == IS_ARRAY) {
if (zend_hash_num_elements(Z_ARRVAL_P(zvalue)) == 0) {
Expand Down
31 changes: 31 additions & 0 deletions ext/curl/tests/curl_setopt_CURLOPT_FOLLOWLOCATION.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
--TEST--
CURLOPT_FOLLOWLOCATION values
--EXTENSIONS--
curl
--SKIPIF--
<?php
include 'skipif-nocaddy.inc';
if (curl_version()['version_number'] < 0x080d00) die('skip requires curl >= 8.13.0');
?>
--FILE--
<?php

for ($i = 0; $i <= CURLFOLLOW_FIRSTONLY; $i ++) {
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, "https://localhost/redirect");
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
var_dump(curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $i));
var_dump(curl_exec($ch));
curl_close($ch);
}
?>
--EXPECTF--
bool(true)
string(%d) "%s"
bool(true)
string(%d) "%s"
bool(true)
string(%d) "%s"
bool(true)
string(%d) "%s"

Loading