[Libevent-users] No Date header in HTTP/1.1 response
Andrew Danforth
acd at weirdness.net
Wed Aug 22 15:03:34 EDT 2007
Any particular reason why you made date and cur static? Seems like there's
little benefit in doing so and you're potentially introducing bugs in
threaded apps if they use the evhttp stuff concurrently.
A
On 8/22/07, Ralph Moritz <ralmoritz at gmail.com> wrote:
>
> Hi,
>
> according to RFC 2616:
>
> Origin servers MUST include a Date header field in all responses,
> except in these cases:
>
> 1. If the response status code is 100 (Continue) or 101 (Switching
> Protocols), the response MAY include a Date header field, at
> the server's option.
>
> 2. If the response status code conveys a server error, e.g. 500
> (Internal Server Error) or 503 (Service Unavailable), and it is
> inconvenient or impossible to generate a valid Date.
>
> 3. If the server does not have a clock that can provide a
> reasonable approximation of the current time, its responses
> MUST NOT include a Date header field. In this case, the rules
> in section 14.18.1 MUST be followed.
>
> So I've modified `evhttp_make_header_response' appropriately. Patch below:
>
> --- http.c.bak 2007-08-16 06:50:57.000000000 +0200
> +++ http.c 2007-08-22 18:48:42.000000000 +0200
> @@ -366,6 +366,25 @@ evhttp_make_header_response(struct evhtt
> evhttp_add_header(req->output_headers,
> "Content-Length", len);
> }
> +
> + /*
> + * Add required Date header to HTTP/1.1 responses.
> + * (Except those with status 100/1)
> + */
> + if ((req->major == 1)
> + && (req->minor == 1)
> + && (req->response_code != 100)
> + && (req->response_code != 101)) {
> + static char date[50];
> + static struct tm cur;
> + time_t t = time(NULL);
> +
> + gmtime_r(&t, &cur);
> + strftime(date, sizeof(date),
> + "%a, %d %b %Y %H:%M:%S GMT", &cur);
> + evhttp_add_header(req->output_headers,
> + "Date", date);
> + }
> }
>
> /* if the request asked for a close, we send a close, too */
>
>
> --
> Ralph Moritz
> Ph: +27 84 626 9070
> GPG Public Key: http://ralphm.info/public.gpg
> _______________________________________________
> Libevent-users mailing list
> Libevent-users at monkey.org
> http://monkey.org/mailman/listinfo/libevent-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://monkeymail.org/archives/libevent-users/attachments/20070822/ccb2d9ab/attachment.htm
More information about the Libevent-users
mailing list