|
|
|
@ -726,16 +726,6 @@ 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")); |
|
|
|
|
|
|
|
|
@ -766,6 +756,17 @@ PHYSICALPATH_FUNC(mod_compress_physical) {
|
|
|
|
|
const char *compression_name = NULL; |
|
|
|
|
int compression_type = 0; |
|
|
|
|
|
|
|
|
|
mtime = strftime_cache_get(srv, sce->st.st_mtime); |
|
|
|
|
|
|
|
|
|
/* try matching original etag of uncompressed version */ |
|
|
|
|
etag_mutate(con->physical.etag, sce->etag); |
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* select best matching encoding */ |
|
|
|
|
if (matched_encodings & HTTP_ACCEPT_ENCODING_BZIP2) { |
|
|
|
|
compression_type = HTTP_ACCEPT_ENCODING_BZIP2; |
|
|
|
@ -778,25 +779,34 @@ PHYSICALPATH_FUNC(mod_compress_physical) {
|
|
|
|
|
compression_name = dflt_deflate; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* deflate it */ |
|
|
|
|
if (p->conf.compress_cache_dir->used) { |
|
|
|
|
if (0 == deflate_file_to_file(srv, con, p, |
|
|
|
|
con->physical.path, sce, compression_type)) { |
|
|
|
|
response_header_overwrite(srv, con, CONST_STR_LEN("Content-Encoding"), compression_name, strlen(compression_name)); |
|
|
|
|
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)); |
|
|
|
|
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)) { |
|
|
|
|
/* try matching etag of compressed version */ |
|
|
|
|
buffer_copy_string_buffer(srv->tmp_buf, sce->etag); |
|
|
|
|
buffer_append_string_len(srv->tmp_buf, CONST_STR_LEN("-")); |
|
|
|
|
buffer_append_string(srv->tmp_buf, compression_name); |
|
|
|
|
etag_mutate(con->physical.etag, srv->tmp_buf); |
|
|
|
|
|
|
|
|
|
if (HANDLER_FINISHED == http_response_handle_cachable(srv, con, mtime)) { |
|
|
|
|
response_header_overwrite(srv, con, CONST_STR_LEN("Content-Encoding"), compression_name, strlen(compression_name)); |
|
|
|
|
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)); |
|
|
|
|
response_header_overwrite(srv, con, CONST_STR_LEN("Content-Type"), CONST_BUF_LEN(sce->content_type)); |
|
|
|
|
return HANDLER_FINISHED; |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
/* deflate it */ |
|
|
|
|
if (p->conf.compress_cache_dir->used) { |
|
|
|
|
if (0 != deflate_file_to_file(srv, con, p, con->physical.path, sce, compression_type)) |
|
|
|
|
return HANDLER_GO_ON; |
|
|
|
|
} else { |
|
|
|
|
if (0 != deflate_file_to_buffer(srv, con, p, con->physical.path, sce, compression_type)) |
|
|
|
|
return HANDLER_GO_ON; |
|
|
|
|
} |
|
|
|
|
response_header_overwrite(srv, con, CONST_STR_LEN("Content-Encoding"), compression_name, strlen(compression_name)); |
|
|
|
|
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)); |
|
|
|
|
response_header_overwrite(srv, con, CONST_STR_LEN("Content-Type"), CONST_BUF_LEN(sce->content_type)); |
|
|
|
|
/* let mod_staticfile handle the cached compressed files, physical path was modified */ |
|
|
|
|
return p->conf.compress_cache_dir->used ? HANDLER_GO_ON : HANDLER_FINISHED; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|