*** src/mod_ssi.c 2007-08-18 20:25:52.000000000 +0800 --- src/mod_ssi.c.etag_lmtime.fix.c 2007-10-11 15:57:10.000000000 +0800 *************** *** 36,41 **** --- 36,46 ---- #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,580 **** --- 580,590 ---- 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,917 **** --- 922,930 ---- 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,1015 **** --- 1023,1052 ---- 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);