Skip to content

Commit 30e791e

Browse files
committed
Fix curl_copy_handle() with CURLINFO_HEADER_OUT
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.
1 parent 501f1a4 commit 30e791e

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

ext/curl/interface.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2074,6 +2074,7 @@ void _php_setup_easy_copy_handlers(php_curl *ch, php_curl *source)
20742074
curl_easy_setopt(ch->cp, CURLOPT_FILE, (void *) ch);
20752075
curl_easy_setopt(ch->cp, CURLOPT_INFILE, (void *) ch);
20762076
curl_easy_setopt(ch->cp, CURLOPT_WRITEHEADER, (void *) ch);
2077+
curl_easy_setopt(ch->cp, CURLOPT_DEBUGDATA, (void *) ch);
20772078

20782079
if (source->handlers->progress) {
20792080
ch->handlers->progress = ecalloc(1, sizeof(php_curl_progress));
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
Test curl_copy_handle() with CURLINFO_HEADER_OUT
3+
--SKIPIF--
4+
<?php include 'skipif.inc'; ?>
5+
--FILE--
6+
<?php
7+
include 'server.inc';
8+
$host = curl_cli_server_start();
9+
10+
$url = "{$host}/get.inc";
11+
$ch = curl_init($url);
12+
13+
curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
14+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
15+
$ch2 = curl_copy_handle($ch);
16+
echo curl_exec($ch), PHP_EOL;
17+
var_dump(strstr(curl_getinfo($ch, CURLINFO_HEADER_OUT), "\r", true));
18+
unset($ch);
19+
echo curl_exec($ch2), PHP_EOL;
20+
var_dump(strstr(curl_getinfo($ch2, CURLINFO_HEADER_OUT), "\r", true));
21+
22+
?>
23+
--EXPECT--
24+
Hello World!
25+
Hello World!
26+
string(21) "GET /get.inc HTTP/1.1"
27+
Hello World!
28+
Hello World!
29+
string(21) "GET /get.inc HTTP/1.1"

0 commit comments

Comments
 (0)