From 3078b3156850d31687cd9a22369aee09b4f63b0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Fri, 18 Jan 2008 09:21:07 +0000 Subject: [PATCH] - generate ETag and Last-Modified headers for mod_ssi based on newest modified include (#1491) git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2053 152afb58-edef-0310-8abb-c4023f1b3aa9 --- NEWS | 1 + src/mod_ssi.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/NEWS b/NEWS index 66a6c89d..43418058 100644 --- a/NEWS +++ b/NEWS @@ -18,6 +18,7 @@ NEWS * add IdleServers and Scoreboard directives in ?auto mode for mod_status (#1507) * open log immediately after daemonizing, fixes SIGPIPEs on startup (#165) * HTTPS env var should be "on" when using mod_extforward and the X-Forwarded-Proto header is set. (#1499) + * generate ETag and Last-Modified headers for mod_ssi based on newest modified include (#1491) - 1.4.18 - 2007-09-09 diff --git a/src/mod_ssi.c b/src/mod_ssi.c index e706e8f4..ff696699 100644 --- a/src/mod_ssi.c +++ b/src/mod_ssi.c @@ -36,6 +36,11 @@ #include #endif +#include "etag.h" + +/* The newest modified time of included files for include statement */ +static volatile time_t include_file_last_mtime = 0; + /* init the plugin data */ INIT_FUNC(mod_ssi_init) { plugin_data *p; @@ -575,6 +580,11 @@ static int process_ssi_stmt(server *srv, connection *con, plugin_data *p, break; case SSI_INCLUDE: chunkqueue_append_file(con->write_queue, p->stat_fn, 0, st.st_size); + + /* Keep the newest mtime of included files */ + if (st.st_mtime > include_file_last_mtime) + include_file_last_mtime = st.st_mtime; + break; } } else { @@ -912,6 +922,9 @@ static int mod_ssi_handle_request(server *srv, connection *con, plugin_data *p) build_ssi_cgi_vars(srv, con, p); p->if_is_false = 0; + /* Reset the modified time of included files */ + include_file_last_mtime = 0; + if (-1 == stream_open(&s, con->physical.path)) { log_error_write(srv, __FILE__, __LINE__, "sb", "stream-open: ", con->physical.path); @@ -1010,6 +1023,30 @@ static int mod_ssi_handle_request(server *srv, connection *con, plugin_data *p) response_header_overwrite(srv, con, CONST_STR_LEN("Content-Type"), CONST_STR_LEN("text/html")); + { + /* Generate "ETag" & "Last-Modified" headers */ + + stat_cache_entry *sce = NULL; + time_t lm_time = 0; + buffer *mtime = NULL; + + stat_cache_get_entry(srv, con, con->physical.path, &sce); + + etag_mutate(con->physical.etag, sce->etag); + response_header_overwrite(srv, con, CONST_STR_LEN("ETag"), CONST_BUF_LEN(con->physical.etag)); + + if (sce->st.st_mtime > include_file_last_mtime) + lm_time = sce->st.st_mtime; + else + lm_time = include_file_last_mtime; + + mtime = strftime_cache_get(srv, lm_time); + response_header_overwrite(srv, con, CONST_STR_LEN("Last-Modified"), CONST_BUF_LEN(mtime)); + } + + /* Reset the modified time of included files */ + include_file_last_mtime = 0; + /* reset physical.path */ buffer_reset(con->physical.path);