Skip to content

Commit 7f98723

Browse files
kelunikpetk
authored andcommitted
Fix #77794: Incorrect Date header format in built-in server
- Fix the date format to be compliant with https://tools.ietf.org/html/rfc7231#section-7.1.1.2 - Fix date format length and use GMT time - Previously, local time was used instead of GMT. - Remove extra whitespace - Simplify string appends in php_cli_server.c
1 parent ec2ecb7 commit 7f98723

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

sapi/cli/php_cli_server.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -349,17 +349,16 @@ static void append_essential_headers(smart_str* buffer, php_cli_server_client *c
349349
struct timeval tv = {0};
350350

351351
if (NULL != (val = zend_hash_str_find_ptr(&client->request.headers, "host", sizeof("host")-1))) {
352-
smart_str_appendl_ex(buffer, "Host", sizeof("Host") - 1, persistent);
353-
smart_str_appendl_ex(buffer, ": ", sizeof(": ") - 1, persistent);
352+
smart_str_appends_ex(buffer, "Host: ", persistent);
354353
smart_str_appends_ex(buffer, val, persistent);
355-
smart_str_appendl_ex(buffer, "\r\n", 2, persistent);
354+
smart_str_appends_ex(buffer, "\r\n", persistent);
356355
}
357356

358357
if (!gettimeofday(&tv, NULL)) {
359-
zend_string *dt = php_format_date("r", 1, tv.tv_sec, 1);
360-
smart_str_appendl_ex(buffer, "Date: ", 6, persistent);
358+
zend_string *dt = php_format_date("D, d M Y H:i:s", sizeof("D, d M Y H:i:s") - 1, tv.tv_sec, 0);
359+
smart_str_appends_ex(buffer, "Date: ", persistent);
361360
smart_str_appends_ex(buffer, dt->val, persistent);
362-
smart_str_appendl_ex(buffer, "\r\n", 2, persistent);
361+
smart_str_appends_ex(buffer, " GMT\r\n", persistent);
363362
zend_string_release(dt);
364363
}
365364

0 commit comments

Comments
 (0)