Ticket #1548: actualized_etags.patch

File actualized_etags.patch, 5.5 kB (added by anonymous, 9 months ago)

etags patch I applied

  • src/base.h

    diff -bur trunk/src/base.h trunk_patched/src/base.h
    old new  
    3333#include "fdevent.h" 
    3434#include "sys-socket.h" 
    3535#include "http_req.h" 
     36#include "etag.h" 
    3637 
    3738#if defined HAVE_LIBSSL && defined HAVE_OPENSSL_SSL_H 
    3839# define USE_OPENSSL 
     
    303304        unsigned short use_ipv6; 
    304305        unsigned short is_ssl; 
    305306        unsigned short allow_http11; 
     307        unsigned short etag_use_inode; 
     308        unsigned short etag_use_mtime; 
     309        unsigned short etag_use_size; 
    306310        unsigned short force_lowercase_filenames; /* if the FS is case-insensitive, force all files to lower-case */ 
    307311        unsigned int max_request_size; 
    308312 
     
    448452        GTimeVal timestamps[TIME_LAST_ELEMENT]; /**< used by timing.h */ 
    449453#endif 
    450454 
     455        /* etag handling */ 
     456        etag_flags_t etag_flags; 
     457 
    451458        int conditional_is_valid[COMP_LAST_ELEMENT]; 
    452459} connection; 
    453460 
  • src/configfile.c

    diff -bur trunk/src/configfile.c trunk_patched/src/configfile.c
    old new  
    9999                { "debug.log-timing",            NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER },     /* 51 */ 
    100100                { "ssl.cipher-list",             NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_SERVER },      /* 52 */ 
    101101                { "ssl.use-sslv2",               NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 53 */ 
     102                { "etag.use-inode",              NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER },     /* 54 */ 
     103                { "etag.use-mtime",              NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER },     /* 55 */ 
     104                { "etag.use-size",               NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER },     /* 56 */ 
    102105 
    103106                { "server.host",                 "use server.bind instead", T_CONFIG_DEPRECATED, T_CONFIG_SCOPE_UNSET }, 
    104107                { "server.docroot",              "use server.document-root instead", T_CONFIG_DEPRECATED, T_CONFIG_SCOPE_UNSET }, 
     
    180183                s->kbytes_per_second = 0; 
    181184                s->allow_http11  = 1; 
    182185                s->range_requests = 1; 
     186                s->etag_use_inode = 1; 
     187                s->etag_use_mtime = 1; 
     188                s->etag_use_size  = 1; 
    183189                s->force_lowercase_filenames = 0; 
    184190                s->global_kbytes_per_second = 0; 
    185191                s->global_bytes_per_second_cnt = 0; 
     
    225231                cv[50].destination = &(s->max_connection_idle); 
    226232                cv[52].destination = s->ssl_cipher_list; 
    227233                cv[53].destination = &(s->ssl_use_sslv2); 
     234                cv[54].destination = &(s->etag_use_inode); 
     235                cv[55].destination = &(s->etag_use_mtime); 
     236                cv[56].destination = &(s->etag_use_size); 
    228237 
    229238                srv->config_storage[i] = s; 
    230239 
     
    297306        PATCH(ssl_ca_file); 
    298307        PATCH(ssl_cipher_list); 
    299308        PATCH(ssl_use_sslv2); 
     309 
     310        PATCH(etag_use_inode); 
     311        PATCH(etag_use_mtime); 
     312        PATCH(etag_use_size); 
    300313        return 0; 
    301314} 
    302315 
     
    342355                                PATCH(max_connection_idle); 
    343356                        } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("mimetype.use-xattr"))) { 
    344357                                PATCH(use_xattr); 
     358                        } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("etag.use-inode"))) { 
     359                                PATCH(etag_use_inode); 
     360                        } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("etag.use-mtime"))) { 
     361                                PATCH(etag_use_mtime); 
     362                        } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("etag.use-size"))) { 
     363                                PATCH(etag_use_size); 
    345364                        } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("ssl.pemfile"))) { 
    346365                                PATCH(ssl_pemfile); 
    347366                        } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("ssl.ca-file"))) { 
     
    385404                        } 
    386405                } 
    387406        } 
     407        con->etag_flags = (con->conf.etag_use_mtime ? ETAG_USE_MTIME : 0) | 
     408                (con->conf.etag_use_inode ? ETAG_USE_INODE : 0) | 
     409                (con->conf.etag_use_size  ? ETAG_USE_SIZE  : 0); 
    388410 
    389411        return 0; 
    390412} 
  • src/etag.c

    diff -bur trunk/src/etag.c trunk_patched/src/etag.c
    old new  
    99        return 0; 
    1010} 
    1111 
    12 int etag_create(buffer *etag, struct stat *st) { 
    13         buffer_copy_off_t(etag, st->st_ino); 
     12int etag_create(buffer *etag, struct stat *st, etag_flags_t flags) { 
     13 
     14        if (0 == flags) return 0; 
     15 
     16        buffer_reset(etag); 
     17 
     18        if (flags & ETAG_USE_INODE) { 
     19               buffer_append_off_t(etag, st->st_ino); 
    1420        buffer_append_string_len(etag, CONST_STR_LEN("-")); 
     21        } 
     22 
     23        if (flags & ETAG_USE_SIZE) { 
    1524        buffer_append_off_t(etag, st->st_size); 
    1625        buffer_append_string_len(etag, CONST_STR_LEN("-")); 
     26        } 
     27 
     28        if (flags & ETAG_USE_MTIME) { 
    1729        buffer_append_long(etag, st->st_mtime); 
     30        } 
    1831 
    1932        return 0; 
    2033} 
  • src/etag.h

    diff -bur trunk/src/etag.h trunk_patched/src/etag.h
    old new  
    66 
    77#include "buffer.h" 
    88 
     9typedef enum { ETAG_USE_INODE = 1, ETAG_USE_MTIME = 2, ETAG_USE_SIZE = 4 } etag_flags_t; 
     10 
    911LI_API int etag_is_equal(buffer *etag, const char *matches); 
    10 LI_API int etag_create(buffer *etag, struct stat *st); 
     12LI_API int etag_create(buffer *etag, struct stat *st, etag_flags_t flags); 
    1113LI_API int etag_mutate(buffer *mut, buffer *etag); 
    1214 
    1315 
  • src/stat_cache.c

    diff -bur trunk/src/stat_cache.c trunk_patched/src/stat_cache.c
    old new  
    470470                                break; 
    471471                        } 
    472472                } 
    473                 etag_create(sce->etag, &(sce->st)); 
     473                etag_create(sce->etag, &(sce->st), con->etag_flags); 
    474474#ifdef HAVE_XATTR 
    475475                if (con->conf.use_xattr && buffer_is_empty(sce->content_type)) { 
    476476                        stat_cache_attr_get(sce->content_type, name->ptr); 
    477477                } 
    478478#endif 
    479479        } else if (S_ISDIR(st.st_mode)) { 
    480                 etag_create(sce->etag, &(sce->st)); 
     480                etag_create(sce->etag, &(sce->st), con->etag_flags); 
    481481        } 
    482482 
    483483        *ret_sce = sce;