From d1bb91108d643c00ba336bbc3ae4ddb2b5b473f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20B=C3=BChler?= Date: Wed, 27 Feb 2008 12:15:38 +0000 Subject: [PATCH] Fix Content-Length header if response body gets removed in connections.c (#1412, part 2) - do not touch if it is a HEAD request (but set file_finished) - body gets removed for req method OPTION and some status codes git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2098 152afb58-edef-0310-8abb-c4023f1b3aa9 --- NEWS | 1 + src/connections.c | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 9e6f5378..cf5c870c 100644 --- a/NEWS +++ b/NEWS @@ -40,6 +40,7 @@ NEWS * check for symlinks after successful pathinfo matching (#1574) * fixed mod-proxy.t to run with a builddir outside of the src dir * do not suppress content on "307 Temporary Redirect" (#1412) + * fixed Content-Length header if response body gets removed in connections.c (#1412, part 2) - 1.4.18 - 2007-09-09 diff --git a/src/connections.c b/src/connections.c index dfde2a5e..a1273685 100644 --- a/src/connections.c +++ b/src/connections.c @@ -398,6 +398,9 @@ static int connection_handle_write_prepare(server *srv, connection *con) { con->uri.path->ptr[0] != '*') { response_header_insert(srv, con, CONST_STR_LEN("Allow"), CONST_STR_LEN("OPTIONS, GET, HEAD, POST")); + con->response.transfer_encoding &= ~HTTP_TRANSFER_ENCODING_CHUNKED; + con->parsed_response &= ~HTTP_CONTENT_LENGTH; + con->http_status = 200; con->file_finished = 1; @@ -512,13 +515,13 @@ static int connection_handle_write_prepare(server *srv, connection *con) { default: /* disable chunked encoding again as we have no body */ con->response.transfer_encoding &= ~HTTP_TRANSFER_ENCODING_CHUNKED; + con->parsed_response &= ~HTTP_CONTENT_LENGTH; chunkqueue_reset(con->write_queue); con->file_finished = 1; break; } - if (con->file_finished) { /* we have all the content and chunked encoding is not used, set a content-length */ @@ -537,7 +540,11 @@ static int connection_handle_write_prepare(server *srv, connection *con) { if ((con->http_status >= 100 && con->http_status < 200) || con->http_status == 204 || con->http_status == 304) { + data_string *ds; /* no Content-Body, no Content-Length */ + if (NULL != (ds = (data_string*) array_get_element(con->response.headers, "Content-Length"))) { + buffer_reset(ds->value); // Headers with empty values are ignored for output + } } else if (qlen >= 0) { /* qlen = 0 is important for Redirects (301, ...) as they MAY have * a content. Browsers are waiting for a Content otherwise @@ -583,6 +590,8 @@ static int connection_handle_write_prepare(server *srv, connection *con) { * a HEAD request has the same as a GET * without the content */ + con->file_finished = 1; + chunkqueue_reset(con->write_queue); con->response.transfer_encoding &= ~HTTP_TRANSFER_ENCODING_CHUNKED; }