From 8d5ef326baa461201b1c948f9b29c5c4ae22533c Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Fri, 7 Sep 2007 01:02:56 +0000 Subject: [PATCH] r14974@catbus: nickm | 2007-09-06 20:59:14 -0400 Changes to http.c: Add a Date header on replies if there is none already set. Also, include time.h unconditionally to be sure that struct tm is declared: every platform has time.h; the conditional should have been for sys/time.h. svn:r412 --- ChangeLog | 3 ++- http.c | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index a2ee6f63..e6c27181 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,5 @@ Changes in current version: - o allow \r or \n individually to separate HTTP headers instead of the standard "\r\n"; from Charles Kerr. + o allow \r or \n individually to separate HTTP headers instead of the standard "\r\n"; from Charles Kerr. o demote most http warnings to debug messages o Fix Solaris compilation; from Magne Mahre + o Add a "Date" header to HTTP responses, as required by HTTP 1.1. \ No newline at end of file diff --git a/http.c b/http.c index 359c1702..da43eb08 100644 --- a/http.c +++ b/http.c @@ -64,9 +64,10 @@ #include #endif #include -#ifdef HAVE_TIME_H -#include +#ifdef HAVE_SYS_TIME_H +#include #endif +#include #include #include @@ -351,6 +352,18 @@ evhttp_make_header_response(struct evhttp_connection *evcon, /* Potentially add headers for unidentified content. */ if (EVBUFFER_LENGTH(req->output_buffer)) { + if (evhttp_find_header(req->output_headers, + "Date") == NULL) { + char date[50]; + struct tm cur; + time_t t = time(NULL); + gmtime_r(&t, &cur); + if (strftime(date, sizeof(date), + "%a, %d %b %Y %H:%M:%S GMT", &cur) != 0) { + evhttp_add_header(req->output_headers, "Date", date); + } + } + if (evhttp_find_header(req->output_headers, "Content-Type") == NULL) { evhttp_add_header(req->output_headers,