Skip to content

Commit 61b0884

Browse files
committed
ext/curl: always returns NULL when Content-Type is empty and there is no error
1 parent a2d1dfa commit 61b0884

2 files changed

Lines changed: 27 additions & 4 deletions

File tree

ext/curl/interface.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2501,7 +2501,7 @@ PHP_FUNCTION(curl_getinfo)
25012501
CAAS("content_type", s_code);
25022502
} else {
25032503
zval retnull;
2504-
ZVAL_FALSE(&retnull);
2504+
ZVAL_NULL(&retnull);
25052505
CAAZ("content_type", &retnull);
25062506
}
25072507
}
@@ -2660,6 +2660,17 @@ PHP_FUNCTION(curl_getinfo)
26602660
RETURN_FALSE;
26612661
}
26622662
break;
2663+
case CURLINFO_CONTENT_TYPE: {
2664+
char *s_code = NULL;
2665+
2666+
if (curl_easy_getinfo(ch->cp, option, &s_code) == CURLE_OK && s_code) {
2667+
RETURN_STRING(s_code);
2668+
} else {
2669+
RETURN_NULL();
2670+
}
2671+
break;
2672+
}
2673+
26632674
default: {
26642675
int type = CURLINFO_TYPEMASK & option;
26652676
switch (type) {

ext/curl/tests/bug16929.phpt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ $host = curl_cli_server_start();
1010
$ch = curl_init();
1111
$url = "{$host}/get.inc?test=emptycontenttype";
1212

13+
# Validate getinfo with empty Content-Type
1314
curl_setopt($ch, CURLOPT_URL, $url);
1415
curl_setopt($ch, CURLOPT_RETURNTRANSFER, $url);
1516
curl_exec($ch);
@@ -21,12 +22,23 @@ var_dump($ct);
2122
$info = curl_getinfo($ch)['content_type'];
2223

2324
var_dump($info);
24-
2525
curl_close($ch);
2626

27+
# Validate getinfo with non-empty Content-Type
28+
$ch = curl_init();
29+
$url = "{$host}/get.inc";
30+
31+
curl_setopt($ch, CURLOPT_URL, $url);
32+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, $url);
33+
curl_exec($ch);
34+
35+
var_dump(curl_getinfo($ch, CURLINFO_CONTENT_TYPE));
36+
var_dump(curl_getinfo($ch)['content_type']);
2737

2838
curl_close($ch);
2939
?>
3040
--EXPECTF--
31-
bool(false)
32-
bool(false)
41+
NULL
42+
NULL
43+
string(%d) "text/html; charset=UTF-8"
44+
string(%d) "text/html; charset=UTF-8"

0 commit comments

Comments
 (0)