Skip to content

Commit a2d1dfa

Browse files
committed
ext/curl: Handle empty Content-Type response by setting content_type to false
- Ensures consistent behavior when Content-Type is missing
1 parent fdd3839 commit a2d1dfa

3 files changed

Lines changed: 36 additions & 1 deletion

File tree

ext/curl/interface.c

Lines changed: 1 addition & 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_NULL(&retnull);
2504+
ZVAL_FALSE(&retnull);
25052505
CAAZ("content_type", &retnull);
25062506
}
25072507
}

ext/curl/tests/bug16929.phpt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--TEST--
2+
Bug #16929 (curl_getinfo($ch, CURLINFO_CONTENT_TYPE) returns false when Content-Type header is not set)
3+
--EXTENSIONS--
4+
curl
5+
--FILE--
6+
<?php
7+
8+
include 'server.inc';
9+
$host = curl_cli_server_start();
10+
$ch = curl_init();
11+
$url = "{$host}/get.inc?test=emptycontenttype";
12+
13+
curl_setopt($ch, CURLOPT_URL, $url);
14+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, $url);
15+
curl_exec($ch);
16+
17+
$ct = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
18+
19+
var_dump($ct);
20+
21+
$info = curl_getinfo($ch)['content_type'];
22+
23+
var_dump($info);
24+
25+
curl_close($ch);
26+
27+
28+
curl_close($ch);
29+
?>
30+
--EXPECTF--
31+
bool(false)
32+
bool(false)

ext/curl/tests/responder/get.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
case 'contenttype':
3030
header('Content-Type: text/plain;charset=utf-8');
3131
break;
32+
case 'emptycontenttype':
33+
header('Content-Type: ');
34+
break;
3235
case 'file':
3336
if (isset($_FILES['file'])) {
3437
echo $_FILES['file']['name'] . '|' . $_FILES['file']['type'] . '|' . $_FILES['file']['size'];

0 commit comments

Comments
 (0)