com php-src: improve date header code: sapi/cli/php_cli_ser ver.c
| From: | Anatol Belski | Date: | Thu, 02 Jun 2016 11:13:54 +0000 |
| Subject: | com php-src: improve date header code: sapi/cli/php_cli_ser ver.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-92272@lists.php.net to get a copy of this message | ||
Commit: d122f4c24a49ab8726f08be5dbf4eeef94a6474c
Author: Anatol Belski <ab@php.net> Thu, 2 Jun 2016 13:13:54 +0200
Parents: a7c0ba2e898b09d4a4aee3ec33be56395ef1fbb1
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=d122f4c24a49ab8726f08be5dbf4eeef94a6474c
Log:
improve date header code
Changed paths:
M sapi/cli/php_cli_server.c
Diff:
diff --git a/sapi/cli/php_cli_server.c b/sapi/cli/php_cli_server.c
index e7c9f43..a9d4a53 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);
} /* }}} */