Allow mod_compress to return 304 (Not Modified); compress ignores the static-file.etags option.(fixes #1884)

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2384 152afb58-edef-0310-8abb-c4023f1b3aa9
svn/tags/lighttpd-1.4.21
Stefan Bühler 15 years ago
parent 4456b579b7
commit fdcb6f60f4

@ -30,6 +30,7 @@ NEWS
* Remove floating point math from server.c (fixes #1402)
* Disable SSLv2 by default
* Use/enforce sane max-connection values (fixes #1803)
* Allow mod_compress to return 304 (Not Modified); compress ignores the static-file.etags option.(fixes #1884)
- 1.4.20 - 2008-09-30

@ -660,6 +660,7 @@ PHYSICALPATH_FUNC(mod_compress_physical) {
size_t m;
off_t max_fsize;
stat_cache_entry *sce = NULL;
buffer *mtime = NULL;
if (con->mode != DIRECT || con->http_status) return HANDLER_GO_ON;
@ -677,7 +678,29 @@ PHYSICALPATH_FUNC(mod_compress_physical) {
max_fsize = p->conf.compress_max_filesize;
stat_cache_get_entry(srv, con, con->physical.path, &sce);
if (con->conf.log_request_handling) {
log_error_write(srv, __FILE__, __LINE__, "s", "-- handling file as static file");
}
if (HANDLER_ERROR == stat_cache_get_entry(srv, con, con->physical.path, &sce)) {
con->http_status = 403;
log_error_write(srv, __FILE__, __LINE__, "sbsb",
"not a regular file:", con->uri.path,
"->", con->physical.path);
return HANDLER_FINISHED;
}
/* we only handle regular files */
#ifdef HAVE_LSTAT
if ((sce->is_symlink == 1) && !con->conf.follow_symlink) {
return HANDLER_GO_ON;
}
#endif
if (!S_ISREG(sce->st.st_mode)) {
return HANDLER_GO_ON;
}
/* don't compress files that are too large as we need to much time to handle them */
if (max_fsize && (sce->st.st_size >> 10) > max_fsize) return HANDLER_GO_ON;
@ -703,6 +726,16 @@ PHYSICALPATH_FUNC(mod_compress_physical) {
/* mimetype found */
data_string *ds;
etag_mutate(con->physical.etag, sce->etag);
mtime = strftime_cache_get(srv, sce->st.st_mtime);
if (HANDLER_FINISHED == http_response_handle_cachable(srv, con, mtime)) {
response_header_overwrite(srv, con, CONST_STR_LEN("Content-Type"), CONST_BUF_LEN(sce->content_type));
response_header_overwrite(srv, con, CONST_STR_LEN("Last-Modified"), CONST_BUF_LEN(mtime));
response_header_overwrite(srv, con, CONST_STR_LEN("ETag"), CONST_BUF_LEN(con->physical.etag));
return HANDLER_FINISHED;
}
/* the response might change according to Accept-Encoding */
response_header_insert(srv, con, CONST_STR_LEN("Vary"), CONST_STR_LEN("Accept-Encoding"));
@ -749,34 +782,18 @@ PHYSICALPATH_FUNC(mod_compress_physical) {
if (p->conf.compress_cache_dir->used) {
if (0 == deflate_file_to_file(srv, con, p,
con->physical.path, sce, compression_type)) {
buffer *mtime;
response_header_overwrite(srv, con, CONST_STR_LEN("Content-Encoding"), compression_name, strlen(compression_name));
mtime = strftime_cache_get(srv, sce->st.st_mtime);
response_header_overwrite(srv, con, CONST_STR_LEN("Last-Modified"), CONST_BUF_LEN(mtime));
etag_mutate(con->physical.etag, sce->etag);
response_header_overwrite(srv, con, CONST_STR_LEN("ETag"), CONST_BUF_LEN(con->physical.etag));
response_header_overwrite(srv, con, CONST_STR_LEN("Content-Type"), CONST_BUF_LEN(sce->content_type));
return HANDLER_GO_ON;
}
} else if (0 == deflate_file_to_buffer(srv, con, p,
con->physical.path, sce, compression_type)) {
buffer *mtime;
response_header_overwrite(srv, con, CONST_STR_LEN("Content-Encoding"), compression_name, strlen(compression_name));
mtime = strftime_cache_get(srv, sce->st.st_mtime);
response_header_overwrite(srv, con, CONST_STR_LEN("Last-Modified"), CONST_BUF_LEN(mtime));
etag_mutate(con->physical.etag, sce->etag);
response_header_overwrite(srv, con, CONST_STR_LEN("ETag"), CONST_BUF_LEN(con->physical.etag));
response_header_overwrite(srv, con, CONST_STR_LEN("Content-Type"), CONST_BUF_LEN(sce->content_type));
return HANDLER_FINISHED;
}
break;

@ -217,4 +217,5 @@ $HTTP["cookie"] =~ "empty-ref" {
$HTTP["host"] == "etag.example.org" {
static-file.etags = "disable"
compress.filetype = ()
}

Loading…
Cancel
Save