diff --git a/trunk/darkhttpd.c b/trunk/darkhttpd.c index 615006d..8844b66 100644 --- a/trunk/darkhttpd.c +++ b/trunk/darkhttpd.c @@ -80,7 +80,7 @@ struct connection int header_dont_free, header_only, http_code; enum { REPLY_GENERATED, REPLY_FROMFILE } reply_type; - char *reply, *lastmod; /* reply lastmod, not request if-mod-since */ + char *reply; int reply_dont_free; FILE *reply_file; size_t reply_length, reply_sent; @@ -665,7 +665,6 @@ static struct connection *new_connection(void) conn->header_only = 0; conn->http_code = 0; conn->reply = NULL; - conn->lastmod = NULL; conn->reply_dont_free = 0; conn->reply_file = NULL; conn->reply_sent = 0; @@ -725,7 +724,6 @@ static void free_connection(struct connection *conn) if (conn->user_agent != NULL) free(conn->user_agent); if (conn->header != NULL && !conn->header_dont_free) free(conn->header); if (conn->reply != NULL && !conn->reply_dont_free) free(conn->reply); - if (conn->lastmod != NULL) free(conn->lastmod); if (conn->reply_file != NULL) fclose(conn->reply_file); } @@ -761,17 +759,17 @@ static void poll_check_timeout(struct connection *conn) /* --------------------------------------------------------------------------- - * Build an RFC1123 date in the static buffer _date[] and return it. + * Format [when] as an RFC1123 date, stored in the specified buffer. The same + * buffer is returned for convenience. */ -#define MAX_DATE_LENGTH 29 /* strlen("Fri, 28 Feb 2003 00:02:08 GMT") */ -static char _date[MAX_DATE_LENGTH + 1]; -static char *rfc1123_date(const time_t when) +#define DATE_LEN 30 /* strlen("Fri, 28 Feb 2003 00:02:08 GMT")+1 */ +static char *rfc1123_date(char *dest, const time_t when) { time_t now = when; - if (strftime(_date, MAX_DATE_LENGTH, + if (strftime(dest, DATE_LEN, "%a, %d %b %Y %H:%M:%S %Z", gmtime(&now) ) == 0) - errx(1, "strftime() failed"); - return _date; + errx(1, "strftime() failed [%s]", dest); + return dest; } @@ -823,13 +821,16 @@ static char *urldecode(const char *url) static void default_reply(struct connection *conn, const int errcode, const char *errname, const char *format, ...) { - char *reason; + char *reason, date[DATE_LEN]; va_list va; va_start(va, format); xvasprintf(&reason, format, va); va_end(va); + /* Only really need to calculate the date once. */ + (void)rfc1123_date(date, time(NULL)); + conn->reply_length = xasprintf(&(conn->reply), "