summaryrefslogtreecommitdiff
path: root/sapi
diff options
context:
space:
mode:
authorAnatol Belski <ab@php.net>2016-06-02 13:13:54 +0200
committerAnatol Belski <ab@php.net>2016-06-02 13:13:54 +0200
commitd122f4c24a49ab8726f08be5dbf4eeef94a6474c (patch)
treeb76f6d9fc21b03238104c347e25682bb02b52d24 /sapi
parenta7c0ba2e898b09d4a4aee3ec33be56395ef1fbb1 (diff)
downloadphp-git-d122f4c24a49ab8726f08be5dbf4eeef94a6474c.tar.gz
improve date header code
Diffstat (limited to 'sapi')
-rw-r--r--sapi/cli/php_cli_server.c32
1 files changed, 17 insertions, 15 deletions
diff --git a/sapi/cli/php_cli_server.c b/sapi/cli/php_cli_server.c
index e7c9f43cb4..a9d4a533b3 100644
--- a/sapi/cli/php_cli_server.c
+++ b/sapi/cli/php_cli_server.c
@@ -340,21 +340,23 @@ static void append_http_status_line(smart_str *buffer, int protocol_version, int
static void append_essential_headers(smart_str* buffer, php_cli_server_client *client, int persistent) /* {{{ */
{
- {
- char *val;
- if (NULL != (val = zend_hash_str_find_ptr(&client->request.headers, "host", sizeof("host")-1))) {
- smart_str_appendl_ex(buffer, "Host", sizeof("Host") - 1, persistent);
- smart_str_appendl_ex(buffer, ": ", sizeof(": ") - 1, persistent);
- smart_str_appends_ex(buffer, val, persistent);
- smart_str_appendl_ex(buffer, "\r\n", 2, persistent);
- }
- }
- time_t t;
- time(&t);
- zend_string *dt = php_format_date("r", 1, t, 1);
- smart_str_appendl_ex(buffer, "Date: ", 6, persistent);
- smart_str_appends_ex(buffer, dt->val, persistent);
- smart_str_appendl_ex(buffer, "\r\n", 2, persistent);
+ char *val;
+ struct timeval tv = {0};
+
+ if (NULL != (val = zend_hash_str_find_ptr(&client->request.headers, "host", sizeof("host")-1))) {
+ smart_str_appendl_ex(buffer, "Host", sizeof("Host") - 1, persistent);
+ smart_str_appendl_ex(buffer, ": ", sizeof(": ") - 1, persistent);
+ smart_str_appends_ex(buffer, val, persistent);
+ smart_str_appendl_ex(buffer, "\r\n", 2, persistent);
+ }
+
+ if (!gettimeofday(&tv, NULL)) {
+ zend_string *dt = php_format_date("r", 1, tv.tv_sec, 1);
+ smart_str_appendl_ex(buffer, "Date: ", 6, persistent);
+ smart_str_appends_ex(buffer, dt->val, persistent);
+ smart_str_appendl_ex(buffer, "\r\n", 2, persistent);
+ zend_string_release(dt);
+ }
smart_str_appendl_ex(buffer, "Connection: close\r\n", sizeof("Connection: close\r\n") - 1, persistent);
} /* }}} */