From ac92ea361637fd6cf39e106ba6a38e65468775b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20B=C3=BChler?= Date: Wed, 23 Apr 2008 19:10:42 +0000 Subject: [PATCH] Allow all http status codes by default; disable body only for 204,205 and 304; generate error pages for 4xx and 5xx (#1639) git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2154 152afb58-edef-0310-8abb-c4023f1b3aa9 --- NEWS | 1 + src/connections.c | 53 ++++++++++++++--------------------------------- tests/request.t | 2 +- 3 files changed, 18 insertions(+), 38 deletions(-) diff --git a/NEWS b/NEWS index 6525bc39..eaf73613 100644 --- a/NEWS +++ b/NEWS @@ -19,6 +19,7 @@ NEWS * Fix mod_fastcgi prefix matching: match the prefix always against url, not the absolute filepath (regardless of check-local) * Overwrite Content-Type header in mod_dirlisting instead of inserting (#1614), patch by Henrik Holst * Handle EINTR in mod_cgi during write() (#1640) + * Allow all http status codes by default; disable body only for 204,205 and 304; generate error pages for 4xx and 5xx (#1639) - 1.4.19 - 2008-03-10 diff --git a/src/connections.c b/src/connections.c index af3686f8..810856a6 100644 --- a/src/connections.c +++ b/src/connections.c @@ -428,21 +428,22 @@ static int connection_handle_write_prepare(server *srv, connection *con) { } switch(con->http_status) { - case 400: /* class: header + custom body */ - case 401: - case 403: - case 404: - case 408: - case 409: - case 411: - case 416: - case 423: - case 500: - case 501: - case 503: - case 505: + case 204: /* class: header only */ + case 205: + case 304: + /* 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; + default: /* class: header + body */ if (con->mode != DIRECT) break; + /* only custom body for 4xx and 5xx */ + if (con->http_status < 400 || con->http_status >= 600) break; + con->file_finished = 0; buffer_reset(con->physical.path); @@ -452,7 +453,8 @@ static int connection_handle_write_prepare(server *srv, connection *con) { stat_cache_entry *sce = NULL; buffer_copy_string_buffer(con->physical.path, con->conf.errorfile_prefix); - buffer_append_string(con->physical.path, get_http_status_body_name(con->http_status)); + buffer_append_long(con->physical.path, con->http_status); + buffer_append_string_len(con->physical.path, CONST_STR_LEN(".html")); if (HANDLER_ERROR != stat_cache_get_entry(srv, con, con->physical.path, &sce)) { con->file_finished = 1; @@ -498,29 +500,6 @@ static int connection_handle_write_prepare(server *srv, connection *con) { response_header_overwrite(srv, con, CONST_STR_LEN("Content-Type"), CONST_STR_LEN("text/html")); } - /* fall through */ - case 207: - case 200: /* class: header + body */ - case 201: - case 300: - case 301: - case 302: - case 303: - case 307: - break; - - case 206: /* write_queue is already prepared */ - break; - case 204: - case 205: /* class: header only */ - case 304: - 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; } diff --git a/tests/request.t b/tests/request.t index d2c88192..ab4f2d2c 100755 --- a/tests/request.t +++ b/tests/request.t @@ -101,7 +101,7 @@ Connection: close Expect: 100-continue EOF ); -$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 417, '-HTTP-Content' => ''} ]; +$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 417 } ]; ok($tf->handle_http($t) == 0, 'Continue, Expect'); ## ranges