summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_http_request.c
diff options
context:
space:
mode:
authorValentin Bartenev <vbart@nginx.com>2018-02-12 16:58:40 +0300
committerValentin Bartenev <vbart@nginx.com>2018-02-12 16:58:40 +0300
commit9646772a00e50c437e0b3204ce6233b6414e1053 (patch)
tree07d32260bd2b109883f865fdefb350f09023740a /src/nxt_http_request.c
parentdc50773e518f6e68109384cb37c91985dbc3fe63 (diff)
downloadunit-9646772a00e50c437e0b3204ce6233b6414e1053.tar.gz
unit-9646772a00e50c437e0b3204ce6233b6414e1053.tar.bz2
HTTP: the Date response header.
Diffstat (limited to 'src/nxt_http_request.c')
-rw-r--r--src/nxt_http_request.c54
1 files changed, 52 insertions, 2 deletions
diff --git a/src/nxt_http_request.c b/src/nxt_http_request.c
index 9c7d4451..0fbcdbbc 100644
--- a/src/nxt_http_request.c
+++ b/src/nxt_http_request.c
@@ -12,6 +12,9 @@ static void nxt_http_request_start(nxt_task_t *task, void *obj, void *data);
static void nxt_http_app_request(nxt_task_t *task, void *obj, void *data);
static void nxt_http_request_done(nxt_task_t *task, void *obj, void *data);
+static u_char *nxt_http_date(u_char *buf, nxt_realtime_t *now, struct tm *tm,
+ size_t size, const char *format);
+
static const nxt_http_request_state_t nxt_http_request_init_state;
static const nxt_http_request_state_t nxt_http_request_body_state;
@@ -258,10 +261,19 @@ void
nxt_http_request_header_send(nxt_task_t *task, nxt_http_request_t *r)
{
u_char *p, *end;
- nxt_http_field_t *server, *content_length;
+ nxt_http_field_t *server, *date, *content_length;
+
+ static nxt_time_string_t date_cache = {
+ (nxt_atomic_uint_t) -1,
+ nxt_http_date,
+ "%s, %02d %s %4d %02d:%02d:%02d GMT",
+ sizeof("Wed, 31 Dec 1986 16:40:00 GMT") - 1,
+ NXT_THREAD_TIME_GMT,
+ NXT_THREAD_TIME_SEC,
+ };
/*
- * TODO: "Server" and "Content-Length" processing should be moved
+ * TODO: "Server", "Date", and "Content-Length" processing should be moved
* to the last header filter.
*/
@@ -272,6 +284,27 @@ nxt_http_request_header_send(nxt_task_t *task, nxt_http_request_t *r)
nxt_http_field_set(server, "Server", "unit/" NXT_VERSION);
+ if (r->resp.date == NULL) {
+ date = nxt_list_zero_add(r->resp.fields);
+ if (nxt_slow_path(date == NULL)) {
+ goto fail;
+ }
+
+ nxt_http_field_name_set(date, "Date");
+
+ p = nxt_mp_nget(r->mem_pool, date_cache.size);
+ if (nxt_slow_path(p == NULL)) {
+ goto fail;
+ }
+
+ (void) nxt_thread_time_string(task->thread, &date_cache, p);
+
+ date->value = p;
+ date->value_length = date_cache.size;
+
+ r->resp.date = date;
+ }
+
if (r->resp.content_length_n != -1
&& (r->resp.content_length == NULL || r->resp.content_length->skip))
{
@@ -389,3 +422,20 @@ nxt_http_request_close_handler(nxt_task_t *task, void *obj, void *data)
handler(task, proto);
}
}
+
+
+static u_char *
+nxt_http_date(u_char *buf, nxt_realtime_t *now, struct tm *tm, size_t size,
+ const char *format)
+{
+ static const char *week[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri",
+ "Sat" };
+
+ static const char *month[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
+
+ return nxt_sprintf(buf, buf + size, format,
+ week[tm->tm_wday], tm->tm_mday,
+ month[tm->tm_mon], tm->tm_year + 1900,
+ tm->tm_hour, tm->tm_min, tm->tm_sec);
+}