Skip to content

Commit 1920ba6

Browse files
committed
Fix #64878: 304 responses return Content-Type header
According to RFC 7232 304 responses should not send a Content-Type header, so the CLI server should comply.
1 parent 6400ef1 commit 1920ba6

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

sapi/cli/php_cli_server.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2185,6 +2185,9 @@ static int php_cli_server_dispatch(php_cli_server *server, php_cli_server_client
21852185
if (!is_static_file) {
21862186
if (SUCCESS == php_cli_server_dispatch_script(server, client TSRMLS_CC)
21872187
|| SUCCESS != php_cli_server_send_error_page(server, client, 500 TSRMLS_CC)) {
2188+
if (SG(sapi_headers).http_response_code == 304) {
2189+
SG(sapi_headers).send_default_content_type = 0;
2190+
}
21882191
php_cli_server_request_shutdown(server, client TSRMLS_CC);
21892192
return SUCCESS;
21902193
}

sapi/cli/tests/bug64878.phpt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
Bug #64878 (304 responses return Content-Type header)
3+
--INI--
4+
allow_url_fopen=1
5+
--SKIPIF--
6+
<?php
7+
include "skipif.inc";
8+
?>
9+
--FILE--
10+
<?php
11+
include "php_cli_server.inc";
12+
php_cli_server_start('header("HTTP/1.1 304 Not Modified")', null);
13+
$headers = get_headers('http://' . PHP_CLI_SERVER_ADDRESS);
14+
echo count(array_filter($headers, function ($value) {
15+
return stripos($value, 'Content-Type') === 0;
16+
}));
17+
?>
18+
--EXPECT--
19+
0

0 commit comments

Comments
 (0)