[Libevent-users] Re: No Date header in HTTP/1.1 response

Ralph Moritz ralmoritz at gmail.com
Thu Aug 23 06:14:09 EDT 2007


On 23/08/07, Jan Kneschke <jan at kneschke.de> wrote:
> This patch will break on non C99 compilers with mixed declaration/code
> errors. Please move the declarations up to the start of this block.

Thanks for spotting that. New patch below. Hopefully this one's kosher.

--- http.c.bak	2007-08-16 06:50:57.000000000 +0200
+++ http.c	2007-08-23 12:11:50.000000000 +0200
@@ -345,6 +345,20 @@ evhttp_make_header_response(struct evhtt

 	/* Potentially add headers for unidentified content. */
 	if (EVBUFFER_LENGTH(req->output_buffer)) {
+		/* Add Date header. (Required by HTTP/1.1) */
+		char date[50];
+		struct tm cur;
+		time_t t = time(NULL);
+		int l;
+
+		gmtime_r(&t, &cur);
+		l = strftime(date, sizeof(date),
+		    "%a, %d %b %Y %H:%M:%S GMT", &cur);
+		if (l != 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,


-- 
Ralph Moritz
Ph: +27 84 626 9070
GPG Public Key: http://ralphm.info/public.gpg


More information about the Libevent-users mailing list