Changeset 1874

Show
Ignore:
Timestamp:
06/15/2007 03:51:16 PM (14 months ago)
Author:
jan
Message:

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@…>)

Location:
branches/lighttpd-1.4.x
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • branches/lighttpd-1.4.x/NEWS

    r1873 r1874  
    66- 1.4.16 -  
    77 
     8  * added static-file.etags, etag.use-inode, etag.use-mtime, etag.use-size 
     9    to customize the generation of ETags for static files. (#1209)  
     10    (patch by <Yusufg@gmail.com>) 
    811  * fixed typecast of NULL on execl() (#1235) 
     12    (patch by F. Denis) 
    913  * fixed circumventing url.access-deny by trailing slash (#1230) 
    1014  * fixed crash on duplicate headers with trailing WS (#1232) 
  • branches/lighttpd-1.4.x/src/base.h

    r1664 r1874  
    270270        unsigned short is_ssl; 
    271271        unsigned short allow_http11; 
     272        unsigned short etag_use_inode; 
     273        unsigned short etag_use_mtime; 
     274        unsigned short etag_use_size; 
    272275        unsigned short force_lowercase_filenames; /* if the FS is case-insensitive, force all files to lower-case */ 
    273276        unsigned short max_request_size; 
  • branches/lighttpd-1.4.x/src/configfile.c

    r1739 r1874  
    9090                { "ssl.cipher-list",             NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_SERVER },      /* 46 */ 
    9191                { "ssl.use-sslv2",               NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 47 */ 
    92  
     92                { "etag.use-inode",             NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 48 */ 
     93                { "etag.use-mtime",             NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 49 */ 
     94                { "etag.use-size",             NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 50 */ 
    9395                { "server.host",                 "use server.bind instead", T_CONFIG_DEPRECATED, T_CONFIG_SCOPE_UNSET }, 
    9496                { "server.docroot",              "use server.document-root instead", T_CONFIG_DEPRECATED, T_CONFIG_SCOPE_UNSET }, 
     
    163165                s->kbytes_per_second = 0; 
    164166                s->allow_http11  = 1; 
     167                s->etag_use_inode = 1; 
     168                s->etag_use_mtime = 1; 
     169                s->etag_use_size  = 1; 
    165170                s->range_requests = 1; 
    166171                s->force_lowercase_filenames = 0; 
     
    207212                cv[46].destination = s->ssl_cipher_list; 
    208213                cv[47].destination = &(s->ssl_use_sslv2); 
     214                cv[48].destination = &(s->etag_use_inode); 
     215                cv[49].destination = &(s->etag_use_mtime); 
     216                cv[50].destination = &(s->etag_use_size); 
    209217 
    210218                srv->config_storage[i] = s; 
     
    281289        PATCH(ssl_cipher_list); 
    282290        PATCH(ssl_use_sslv2); 
    283  
    284  
     291        PATCH(etag_use_inode); 
     292        PATCH(etag_use_mtime); 
     293        PATCH(etag_use_size); 
     294  
    285295        return 0; 
    286296} 
     
    324334                        } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("mimetype.use-xattr"))) { 
    325335                                PATCH(use_xattr); 
     336                        } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("etag.use-inode"))) { 
     337                                PATCH(etag_use_inode); 
     338                        } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("etag.use-mtime"))) { 
     339                                PATCH(etag_use_mtime); 
     340                        } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("etag.use-size"))) { 
     341                                PATCH(etag_use_size); 
    326342                        } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("ssl.pemfile"))) { 
    327343                                PATCH(ssl_pemfile); 
  • branches/lighttpd-1.4.x/src/etag.c

    r1371 r1874  
    99} 
    1010 
    11 int etag_create(buffer *etag, struct stat *st) { 
    12         buffer_copy_off_t(etag, st->st_ino); 
    13         buffer_append_string_len(etag, CONST_STR_LEN("-")); 
    14         buffer_append_off_t(etag, st->st_size); 
    15         buffer_append_string_len(etag, CONST_STR_LEN("-")); 
    16         buffer_append_long(etag, st->st_mtime); 
     11int etag_create(buffer *etag, struct stat *st,etag_flags_t flags) { 
     12        if (0 == flags) return 0; 
     13         
     14        if (flags & ETAG_USE_INODE) { 
     15                buffer_copy_off_t(etag, st->st_ino); 
     16                buffer_append_string_len(etag, CONST_STR_LEN("-")); 
     17        } 
     18         
     19        if (flags & ETAG_USE_SIZE) { 
     20                buffer_append_off_t(etag, st->st_size); 
     21                buffer_append_string_len(etag, CONST_STR_LEN("-")); 
     22        } 
     23         
     24        if (flags & ETAG_USE_MTIME) { 
     25                buffer_append_long(etag, st->st_mtime); 
     26        } 
    1727 
    1828        return 0; 
  • branches/lighttpd-1.4.x/src/etag.h

    r1371 r1874  
    88#include "buffer.h" 
    99 
     10typedef enum { ETAG_USE_INODE = 1, ETAG_USE_MTIME = 2, ETAG_USE_SIZE = 4 } etag_flags_t; 
     11 
    1012int etag_is_equal(buffer *etag, const char *matches); 
    11 int etag_create(buffer *etag, struct stat *st); 
     13int etag_create(buffer *etag, struct stat *st, etag_flags_t flags); 
    1214int etag_mutate(buffer *mut, buffer *etag); 
    1315 
  • branches/lighttpd-1.4.x/src/mod_staticfile.c

    r1725 r1874  
    2626typedef struct { 
    2727        array *exclude_ext; 
     28        unsigned short etags_used; 
    2829} plugin_config; 
    2930 
     
    8384        config_values_t cv[] = { 
    8485                { "static-file.exclude-extensions", NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION },       /* 0 */ 
     86                { "static-file.etags",    NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 1 */ 
    8587                { NULL,                         NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET } 
    8688        }; 
     
    9597                s = calloc(1, sizeof(plugin_config)); 
    9698                s->exclude_ext    = array_init(); 
     99                s->etags_used     = 1; 
    97100 
    98101                cv[0].destination = s->exclude_ext; 
     102                cv[1].destination = &(s->etags_used); 
    99103 
    100104                p->config_storage[i] = s; 
     
    115119 
    116120        PATCH(exclude_ext); 
     121        PATCH(etags_used); 
    117122 
    118123        /* skip the first, the global context */ 
     
    130135                        if (buffer_is_equal_string(du->key, CONST_STR_LEN("static-file.exclude-extensions"))) { 
    131136                                PATCH(exclude_ext); 
    132                         } 
     137                        } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("static-file.etags"))) { 
     138                                PATCH(etags_used); 
     139                        }  
    133140                } 
    134141        } 
     
    447454 
    448455        if (allow_caching) { 
    449                 if (NULL == array_get_element(con->response.headers, "ETag")) { 
    450                         /* generate e-tag */ 
    451                         etag_mutate(con->physical.etag, sce->etag); 
    452  
    453                         response_header_overwrite(srv, con, CONST_STR_LEN("ETag"), CONST_BUF_LEN(con->physical.etag)); 
     456                etag_flags_t flags; 
     457 
     458                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); 
     459 
     460                if (p->conf.etags_used && flags != 0 && !buffer_is_empty(sce->etag)) { 
     461                        if (NULL == array_get_element(con->response.headers, "ETag")) { 
     462                                /* generate e-tag */ 
     463                                etag_mutate(con->physical.etag, sce->etag); 
     464 
     465                                response_header_overwrite(srv, con, CONST_STR_LEN("ETag"), CONST_BUF_LEN(con->physical.etag)); 
     466                        } 
    454467                } 
    455468 
  • branches/lighttpd-1.4.x/src/stat_cache.c

    r1863 r1874  
    609609                        } 
    610610                } 
    611                 etag_create(sce->etag, &(sce->st)); 
     611                etag_create(sce->etag, &(sce->st), 
     612                        (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)); 
    612613#ifdef HAVE_XATTR 
    613614                if (con->conf.use_xattr && buffer_is_empty(sce->content_type)) { 
     
    616617#endif 
    617618        } else if (S_ISDIR(st.st_mode)) { 
    618                 etag_create(sce->etag, &(sce->st)); 
     619                etag_create(sce->etag, &(sce->st), 
     620                        (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)); 
    619621        } 
    620622