summaryrefslogtreecommitdiff
path: root/src/response.c
diff options
context:
space:
mode:
authorGlenn Strauss <gstrauss@gluelogic.com>2020-11-22 02:41:11 -0500
committerGlenn Strauss <gstrauss@gluelogic.com>2020-12-24 16:13:20 -0500
commit122094e3e3bfffd36b1df41f76887a8b64aca12d (patch)
treeb6b591d181e4a12d81d872d9313485175ed9a749 /src/response.c
parent48a8e893a7c9e5d6e2e34974f6ca0d774c430362 (diff)
downloadlighttpd-git-122094e3e3bfffd36b1df41f76887a8b64aca12d.tar.gz
[multiple] employ http_date.h, sys-time.h
- replace use of strptime() w/ implementation specialized for HTTP dates - use thread-safe gmtime_r(), localtime_r() (replace localtime, gmtime)
Diffstat (limited to 'src/response.c')
-rw-r--r--src/response.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/src/response.c b/src/response.c
index 1bac6eea..bed75e9d 100644
--- a/src/response.c
+++ b/src/response.c
@@ -10,6 +10,7 @@
#include "stat_cache.h"
#include "chunk.h"
#include "http_chunk.h"
+#include "http_date.h"
#include "plugin.h"
@@ -129,21 +130,17 @@ http_response_write_header (request_st * const r)
}
if (!light_btst(r->resp_htags, HTTP_HEADER_DATE)) {
- static time_t tlast;
- static char tstr[32]; /* 30-chars for "%a, %d %b %Y %H:%M:%S GMT" */
- static size_t tlen;
+ /* HTTP/1.1 and later requires a Date: header */
+ /* "\r\nDate: " 8-chars + 30-chars "%a, %d %b %Y %H:%M:%S GMT" + '\0' */
+ static time_t tlast = 0;
+ static char tstr[40] = "\r\nDate: ";
/* cache the generated timestamp */
const time_t cur_ts = log_epoch_secs;
- if (tlast != cur_ts) {
- tlast = cur_ts;
- tlen = strftime(tstr, sizeof(tstr),
- "%a, %d %b %Y %H:%M:%S GMT", gmtime(&tlast));
- }
+ if (__builtin_expect ( (tlast != cur_ts), 0))
+ http_date_time_to_str(tstr+8, sizeof(tstr)-8, (tlast = cur_ts));
- /* HTTP/1.1 and later requires a Date: header */
- buffer_append_string_len(b, CONST_STR_LEN("\r\nDate: "));
- buffer_append_string_len(b, tstr, tlen);
+ buffer_append_string_len(b, tstr, 37);
}
if (!light_btst(r->resp_htags, HTTP_HEADER_SERVER)) {