Changeset 969

Show
Ignore:
Timestamp:
12/31/07 21:17:48 (11 months ago)
Author:
adefacc
Message:

Added server max-age support per mime-type

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • cherokee/trunk/ChangeLog

    r960 r969  
     12007-12-31  A.D.F  <adefacc@tin.it> 
     2 
     3        * mime.c 
     4          - changed cherokee_mime_load_mime_types() 
     5            to interpret a sequence of digits preceded by '.' 
     6            as a max-age value in seconds for that mime type 
     7            (instead of interpreting it as a file extension); 
     8            i.e. to set a max-age of 65 seconds in mime.types for html files: 
     9 
     10            # mime type       [ .number ]  extension1 [ extensions ... ] 
     11            text/html           .65     html htm shtml 
     12 
    1132007-12-21  A.D.F  <adefacc@tin.it> 
    214 
  • cherokee/trunk/cherokee/mime.c

    r835 r969  
    116116{ 
    117117        ret_t              ret; 
     118        cuint_t            maxage = 0; 
    118119        char              *p; 
    119120        char              *end; 
     
    176177                cherokee_mime_entry_set_type (entry, type.buf); 
    177178                         
    178                 /* Adds its extensions 
    179                  */ 
    180                 p = tmp; 
    181                 while (p < nl) { 
     179                /* Adds its max-age and file extensions. 
     180                 */ 
     181                for (p = tmp; p < nl; p = tmp) { 
    182182                        cherokee_buffer_clean (&ext); 
    183183                         
    184184                        /* Look for the next extension 
    185185                         */ 
    186                         while ((*p == ' ') || (*p == '\t')) p++; 
    187                         if (p >= nl) break; 
     186                        while ((*p == ' ') || (*p == '\t')) 
     187                                p++; 
     188                        if (p >= nl) 
     189                                break; 
    188190 
    189191                        c1 = strchr (p, ' '); 
     
    191193 
    192194                        tmp  = cherokee_min_str (c1, c2); 
    193                         if (tmp == NULL) tmp = nl; 
    194  
    195                         /* Add it to the table 
     195                        if (tmp == NULL) 
     196                                tmp = nl; 
     197 
     198                        if (*p == '.') { 
     199                                char *p2 = p; 
     200 
     201                                /* It could be a max-age value. 
     202                                 */ 
     203                                for (++p2, len = 0; p2 < tmp; ++p2, ++len) { 
     204                                        if (!isdigit(*p2)) 
     205                                                break; 
     206                                } 
     207                                /* If it is too short or 
     208                                 * it is not made of digits only 
     209                                 * then ignore this value. 
     210                                 */ 
     211                                if (len < 1 || p2 < tmp) 
     212                                        continue; 
     213 
     214                                /* Convert max-age value. 
     215                                 */ 
     216                                if (len > 9) { 
     217                                        maxage = (cuint_t) 999999999; 
     218                                } else { 
     219                                        maxage = (cuint_t) atoi(p + 1); 
     220                                } 
     221 
     222                                /* Set max-age value. 
     223                                 */ 
     224                                cherokee_mime_entry_set_maxage(entry, maxage); 
     225 
     226                                TRACE(ENTRIES, "Set max-age %9u, mime type '%s'\n", maxage, type.buf); 
     227 
     228                                continue; 
     229                        } 
     230 
     231                        /* Add this file extension to the table. 
    196232                         */ 
    197233                        cherokee_buffer_add (&ext, p, tmp-p); 
    198234                        cherokee_avl_add (&mime->mime_table, &ext, entry); 
    199235 
    200                         TRACE(ENTRIES, "Adding mime '%s' -> '%s'\n", ext.buf, type.buf); 
    201  
    202                         p = tmp; 
     236                        TRACE(ENTRIES, "Added mime '%s' -> '%s'\n", ext.buf, type.buf); 
    203237                } 
    204238