From 760baed402d5074c990a932b781728395e657eea Mon Sep 17 00:00:00 2001 From: Glenn Strauss Date: Wed, 13 Apr 2016 01:04:39 -0400 Subject: [PATCH] [mod_expire] reset caching response headers for error docs (fixes #1919) remove Cache-Control and Expires headers before handling error docs (caching headers may have been set by mod_expire before http status was determined to be an error) x-ref: "mod_expires sends headers on 404 responses" https://redmine.lighttpd.net/issues/1919 --- NEWS | 1 + src/connections.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/NEWS b/NEWS index ea1dc834..75be21a7 100644 --- a/NEWS +++ b/NEWS @@ -68,6 +68,7 @@ NEWS * [mod_magnet] rename var for clarity (fixes #1483) * [mod_extforward] reset cond_cache for scheme (fixes #1499) * [mod_webdav] readdir POSIX compat (fixes #1826) + * [mod_expire] reset caching response headers for error docs (fixes #1919) - 1.4.39 - 2016-01-02 * [core] fix memset_s call (fixes #2698) diff --git a/src/connections.c b/src/connections.c index f33fcd69..25925925 100644 --- a/src/connections.c +++ b/src/connections.c @@ -415,6 +415,17 @@ static int connection_handle_read(server *srv, connection *con) { return 0; } +static void connection_handle_errdoc_init(connection *con) { + /* reset caching response headers potentially added by mod_expire */ + data_string *ds; + if (NULL != (ds = (data_string*) array_get_element(con->response.headers, "Expires"))) { + buffer_reset(ds->value); /* Headers with empty values are ignored for output */ + } + if (NULL != (ds = (data_string*) array_get_element(con->response.headers, "Cache-Control"))) { + buffer_reset(ds->value); /* Headers with empty values are ignored for output */ + } +} + static int connection_handle_write_prepare(server *srv, connection *con) { if (con->mode == DIRECT) { /* static files */ @@ -474,6 +485,7 @@ static int connection_handle_write_prepare(server *srv, connection *con) { con->file_finished = 0; buffer_reset(con->physical.path); + connection_handle_errdoc_init(con); /* try to send static errorfile */ if (!buffer_string_is_empty(con->conf.errorfile_prefix)) { @@ -1309,6 +1321,7 @@ int connection_state_machine(server *srv, connection *con) { buffer_copy_buffer(con->request.uri, con->error_handler); } buffer_reset(con->physical.path); + connection_handle_errdoc_init(con); con->in_error_handler = 1;