from trunk: fix connection keep-alive behavior for HTTP/1.0

svn:r824
This commit is contained in:
Niels Provos 2008-05-15 01:58:32 +00:00
parent 8d8cff549a
commit 17515971a0
2 changed files with 24 additions and 13 deletions

View File

@ -1,3 +1,6 @@
Changes in 1.4.5-stable:
o Fix connection keep-alive behavior for HTTP/1.0
Changes in 1.4.4-stable:
o Correct the documentation on buffer printf functions.
o Don't warn on unimplemented epoll_create(): this isn't a problem, just a reason to fall back to poll or select.
@ -65,8 +68,6 @@ Changes in 1.4.1-beta:
o When building with GCC, use the "format" attribute to verify type correctness of calls to printf-like functions.
o removed linger from http server socket; reported by Ilya Martynov
o Rewrite win32.c backend to be O(n lg n) rather than O(n^2)
Changes in 1.4.0-beta:
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

32
http.c
View File

@ -393,25 +393,35 @@ static void
evhttp_make_header_response(struct evhttp_connection *evcon,
struct evhttp_request *req)
{
int is_keepalive = evhttp_is_connection_keepalive(req->input_headers);
char line[1024];
snprintf(line, sizeof(line), "HTTP/%d.%d %d %s\r\n",
req->major, req->minor, req->response_code,
req->response_code_line);
evbuffer_add(evcon->output_buffer, line, strlen(line));
if (req->major == 1 && req->minor == 1)
evhttp_maybe_add_date_header(req->output_headers);
if (req->major == 1) {
if (req->minor == 1)
evhttp_maybe_add_date_header(req->output_headers);
if (req->major == 1 &&
(req->minor == 1 ||
evhttp_is_connection_keepalive(req->input_headers))) {
/*
* we need to add the content length if the user did
* not give it, this is required for persistent
* connections to work.
/*
* if the protocol is 1.0; and the connection was keep-alive
* we need to add a keep-alive header, too.
*/
evhttp_maybe_add_content_length_header(req->output_headers,
(long)EVBUFFER_LENGTH(req->output_buffer));
if (req->minor == 0 && is_keepalive)
evhttp_add_header(req->output_headers,
"Connection", "keep-alive");
if (req->minor == 1 || is_keepalive) {
/*
* we need to add the content length if the
* user did not give it, this is required for
* persistent connections to work.
*/
evhttp_maybe_add_content_length_header(
req->output_headers,
(long)EVBUFFER_LENGTH(req->output_buffer));
}
}
/* Potentially add headers for unidentified content. */