added static-file.etags, etag.use-inode, etag.use-mtime,
etag.use-size to customize the generation of ETags for static files. (fixes #1209) (patch by <Yusufg@gmail.com>) git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@1874 152afb58-edef-0310-8abb-c4023f1b3aa9svn/tags/lighttpd-1.4.16
parent
d12d86d777
commit
b2a96c959a
4
NEWS
4
NEWS
|
@ -5,7 +5,11 @@ NEWS
|
|||
|
||||
- 1.4.16 -
|
||||
|
||||
* added static-file.etags, etag.use-inode, etag.use-mtime, etag.use-size
|
||||
to customize the generation of ETags for static files. (#1209)
|
||||
(patch by <Yusufg@gmail.com>)
|
||||
* fixed typecast of NULL on execl() (#1235)
|
||||
(patch by F. Denis)
|
||||
* fixed circumventing url.access-deny by trailing slash (#1230)
|
||||
* fixed crash on duplicate headers with trailing WS (#1232)
|
||||
* fixed accepting more connections then requested (#1216)
|
||||
|
|
|
@ -269,6 +269,9 @@ typedef struct {
|
|||
unsigned short use_ipv6;
|
||||
unsigned short is_ssl;
|
||||
unsigned short allow_http11;
|
||||
unsigned short etag_use_inode;
|
||||
unsigned short etag_use_mtime;
|
||||
unsigned short etag_use_size;
|
||||
unsigned short force_lowercase_filenames; /* if the FS is case-insensitive, force all files to lower-case */
|
||||
unsigned short max_request_size;
|
||||
|
||||
|
|
|
@ -89,7 +89,9 @@ static int config_insert(server *srv) {
|
|||
{ "server.core-files", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 45 */
|
||||
{ "ssl.cipher-list", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_SERVER }, /* 46 */
|
||||
{ "ssl.use-sslv2", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 47 */
|
||||
|
||||
{ "etag.use-inode", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 48 */
|
||||
{ "etag.use-mtime", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 49 */
|
||||
{ "etag.use-size", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 50 */
|
||||
{ "server.host", "use server.bind instead", T_CONFIG_DEPRECATED, T_CONFIG_SCOPE_UNSET },
|
||||
{ "server.docroot", "use server.document-root instead", T_CONFIG_DEPRECATED, T_CONFIG_SCOPE_UNSET },
|
||||
{ "server.virtual-root", "load mod_simple_vhost and use simple-vhost.server-root instead", T_CONFIG_DEPRECATED, T_CONFIG_SCOPE_UNSET },
|
||||
|
@ -162,6 +164,9 @@ static int config_insert(server *srv) {
|
|||
#endif
|
||||
s->kbytes_per_second = 0;
|
||||
s->allow_http11 = 1;
|
||||
s->etag_use_inode = 1;
|
||||
s->etag_use_mtime = 1;
|
||||
s->etag_use_size = 1;
|
||||
s->range_requests = 1;
|
||||
s->force_lowercase_filenames = 0;
|
||||
s->global_kbytes_per_second = 0;
|
||||
|
@ -206,6 +211,9 @@ static int config_insert(server *srv) {
|
|||
|
||||
cv[46].destination = s->ssl_cipher_list;
|
||||
cv[47].destination = &(s->ssl_use_sslv2);
|
||||
cv[48].destination = &(s->etag_use_inode);
|
||||
cv[49].destination = &(s->etag_use_mtime);
|
||||
cv[50].destination = &(s->etag_use_size);
|
||||
|
||||
srv->config_storage[i] = s;
|
||||
|
||||
|
@ -280,8 +288,10 @@ int config_setup_connection(server *srv, connection *con) {
|
|||
PATCH(ssl_ca_file);
|
||||
PATCH(ssl_cipher_list);
|
||||
PATCH(ssl_use_sslv2);
|
||||
|
||||
|
||||
PATCH(etag_use_inode);
|
||||
PATCH(etag_use_mtime);
|
||||
PATCH(etag_use_size);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -323,6 +333,12 @@ int config_patch_connection(server *srv, connection *con, comp_key_t comp) {
|
|||
PATCH(max_read_idle);
|
||||
} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("mimetype.use-xattr"))) {
|
||||
PATCH(use_xattr);
|
||||
} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("etag.use-inode"))) {
|
||||
PATCH(etag_use_inode);
|
||||
} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("etag.use-mtime"))) {
|
||||
PATCH(etag_use_mtime);
|
||||
} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("etag.use-size"))) {
|
||||
PATCH(etag_use_size);
|
||||
} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("ssl.pemfile"))) {
|
||||
PATCH(ssl_pemfile);
|
||||
} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("ssl.ca-file"))) {
|
||||
|
|
22
src/etag.c
22
src/etag.c
|
@ -8,12 +8,22 @@ int etag_is_equal(buffer *etag, const char *matches) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int etag_create(buffer *etag, struct stat *st) {
|
||||
buffer_copy_off_t(etag, st->st_ino);
|
||||
buffer_append_string_len(etag, CONST_STR_LEN("-"));
|
||||
buffer_append_off_t(etag, st->st_size);
|
||||
buffer_append_string_len(etag, CONST_STR_LEN("-"));
|
||||
buffer_append_long(etag, st->st_mtime);
|
||||
int etag_create(buffer *etag, struct stat *st,etag_flags_t flags) {
|
||||
if (0 == flags) return 0;
|
||||
|
||||
if (flags & ETAG_USE_INODE) {
|
||||
buffer_copy_off_t(etag, st->st_ino);
|
||||
buffer_append_string_len(etag, CONST_STR_LEN("-"));
|
||||
}
|
||||
|
||||
if (flags & ETAG_USE_SIZE) {
|
||||
buffer_append_off_t(etag, st->st_size);
|
||||
buffer_append_string_len(etag, CONST_STR_LEN("-"));
|
||||
}
|
||||
|
||||
if (flags & ETAG_USE_MTIME) {
|
||||
buffer_append_long(etag, st->st_mtime);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -7,8 +7,10 @@
|
|||
|
||||
#include "buffer.h"
|
||||
|
||||
typedef enum { ETAG_USE_INODE = 1, ETAG_USE_MTIME = 2, ETAG_USE_SIZE = 4 } etag_flags_t;
|
||||
|
||||
int etag_is_equal(buffer *etag, const char *matches);
|
||||
int etag_create(buffer *etag, struct stat *st);
|
||||
int etag_create(buffer *etag, struct stat *st, etag_flags_t flags);
|
||||
int etag_mutate(buffer *mut, buffer *etag);
|
||||
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
typedef struct {
|
||||
array *exclude_ext;
|
||||
unsigned short etags_used;
|
||||
} plugin_config;
|
||||
|
||||
typedef struct {
|
||||
|
@ -82,6 +83,7 @@ SETDEFAULTS_FUNC(mod_staticfile_set_defaults) {
|
|||
|
||||
config_values_t cv[] = {
|
||||
{ "static-file.exclude-extensions", NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION }, /* 0 */
|
||||
{ "static-file.etags", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 1 */
|
||||
{ NULL, NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
|
||||
};
|
||||
|
||||
|
@ -94,8 +96,10 @@ SETDEFAULTS_FUNC(mod_staticfile_set_defaults) {
|
|||
|
||||
s = calloc(1, sizeof(plugin_config));
|
||||
s->exclude_ext = array_init();
|
||||
s->etags_used = 1;
|
||||
|
||||
cv[0].destination = s->exclude_ext;
|
||||
cv[1].destination = &(s->etags_used);
|
||||
|
||||
p->config_storage[i] = s;
|
||||
|
||||
|
@ -114,6 +118,7 @@ static int mod_staticfile_patch_connection(server *srv, connection *con, plugin_
|
|||
plugin_config *s = p->config_storage[0];
|
||||
|
||||
PATCH(exclude_ext);
|
||||
PATCH(etags_used);
|
||||
|
||||
/* skip the first, the global context */
|
||||
for (i = 1; i < srv->config_context->used; i++) {
|
||||
|
@ -129,7 +134,9 @@ static int mod_staticfile_patch_connection(server *srv, connection *con, plugin_
|
|||
|
||||
if (buffer_is_equal_string(du->key, CONST_STR_LEN("static-file.exclude-extensions"))) {
|
||||
PATCH(exclude_ext);
|
||||
}
|
||||
} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("static-file.etags"))) {
|
||||
PATCH(etags_used);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -446,11 +453,17 @@ URIHANDLER_FUNC(mod_staticfile_subrequest) {
|
|||
response_header_overwrite(srv, con, CONST_STR_LEN("Accept-Ranges"), CONST_STR_LEN("bytes"));
|
||||
|
||||
if (allow_caching) {
|
||||
if (NULL == array_get_element(con->response.headers, "ETag")) {
|
||||
/* generate e-tag */
|
||||
etag_mutate(con->physical.etag, sce->etag);
|
||||
etag_flags_t flags;
|
||||
|
||||
response_header_overwrite(srv, con, CONST_STR_LEN("ETag"), CONST_BUF_LEN(con->physical.etag));
|
||||
flags = (con->conf.etag_use_mtime ? ETAG_USE_MTIME : 0) | (con->conf.etag_use_inode ? ETAG_USE_INODE : 0) | (con->conf.etag_use_size ? ETAG_USE_SIZE : 0);
|
||||
|
||||
if (p->conf.etags_used && flags != 0 && !buffer_is_empty(sce->etag)) {
|
||||
if (NULL == array_get_element(con->response.headers, "ETag")) {
|
||||
/* generate e-tag */
|
||||
etag_mutate(con->physical.etag, sce->etag);
|
||||
|
||||
response_header_overwrite(srv, con, CONST_STR_LEN("ETag"), CONST_BUF_LEN(con->physical.etag));
|
||||
}
|
||||
}
|
||||
|
||||
/* prepare header */
|
||||
|
|
|
@ -608,14 +608,16 @@ handler_t stat_cache_get_entry(server *srv, connection *con, buffer *name, stat_
|
|||
break;
|
||||
}
|
||||
}
|
||||
etag_create(sce->etag, &(sce->st));
|
||||
etag_create(sce->etag, &(sce->st),
|
||||
(con->conf.etag_use_mtime ? ETAG_USE_MTIME : 0) | (con->conf.etag_use_inode ? ETAG_USE_INODE : 0) | (con->conf.etag_use_size ? ETAG_USE_SIZE : 0));
|
||||
#ifdef HAVE_XATTR
|
||||
if (con->conf.use_xattr && buffer_is_empty(sce->content_type)) {
|
||||
stat_cache_attr_get(sce->content_type, name->ptr);
|
||||
}
|
||||
#endif
|
||||
} else if (S_ISDIR(st.st_mode)) {
|
||||
etag_create(sce->etag, &(sce->st));
|
||||
etag_create(sce->etag, &(sce->st),
|
||||
(con->conf.etag_use_mtime ? ETAG_USE_MTIME : 0) | (con->conf.etag_use_inode ? ETAG_USE_INODE : 0) | (con->conf.etag_use_size ? ETAG_USE_SIZE : 0));
|
||||
}
|
||||
|
||||
#ifdef HAVE_FAM_H
|
||||
|
|
Loading…
Reference in New Issue