Skip to content

Commit

Permalink
Fix curl_copy_handle() with CURLINFO_HEADER_OUT
Browse files Browse the repository at this point in the history
The CURLOPT_DEBUGDATA will point to the old curl handle after
copying. Update it to point to the new handle.

We don't separately store whether CURLINFO_HEADER_OUT is enabled,
so I'm doing this unconditionally. It should be harmless if
CURLOPT_DEBUGFUNCTION is not used.
  • Loading branch information
nikic committed Aug 31, 2021
1 parent 501f1a4 commit 30e791e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions ext/curl/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -2074,6 +2074,7 @@ void _php_setup_easy_copy_handlers(php_curl *ch, php_curl *source)
curl_easy_setopt(ch->cp, CURLOPT_FILE, (void *) ch);
curl_easy_setopt(ch->cp, CURLOPT_INFILE, (void *) ch);
curl_easy_setopt(ch->cp, CURLOPT_WRITEHEADER, (void *) ch);
curl_easy_setopt(ch->cp, CURLOPT_DEBUGDATA, (void *) ch);

if (source->handlers->progress) {
ch->handlers->progress = ecalloc(1, sizeof(php_curl_progress));
Expand Down
29 changes: 29 additions & 0 deletions ext/curl/tests/curl_copy_handle_basic_009.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--TEST--
Test curl_copy_handle() with CURLINFO_HEADER_OUT
--SKIPIF--
<?php include 'skipif.inc'; ?>
--FILE--
<?php
include 'server.inc';
$host = curl_cli_server_start();

$url = "{$host}/get.inc";
$ch = curl_init($url);

curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$ch2 = curl_copy_handle($ch);
echo curl_exec($ch), PHP_EOL;
var_dump(strstr(curl_getinfo($ch, CURLINFO_HEADER_OUT), "\r", true));
unset($ch);
echo curl_exec($ch2), PHP_EOL;
var_dump(strstr(curl_getinfo($ch2, CURLINFO_HEADER_OUT), "\r", true));

?>
--EXPECT--
Hello World!
Hello World!
string(21) "GET /get.inc HTTP/1.1"
Hello World!
Hello World!
string(21) "GET /get.inc HTTP/1.1"

0 comments on commit 30e791e

Please sign in to comment.