Sep 302012
 

Création de l’Expires à partir du cache-control max-age si il est présent et différent de 0, puis suppression du max-age.

Ajoutez au début de la configuration :

C{
        #include <string.h>
        #include <stdlib.h>
 
        void TIM_format(double t, char *p);
        double TIM_real(void);
}C

Et dans le vcl_deliver :

if ( resp.http.Cache-Control ~ "max-age" && ! resp.http.Cache-Control ~ "max-age=0" ) {
        C{
                 char *cache = VRT_GetHdr(sp, HDR_RESP, "\016cache-control:");
                 char date[40];
                 int max_age = -1;
                 int want_equals = 0;
                 if(cache) {
                         while(*cache != '\0') {
                                 if (want_equals && *cache == '=') {
                                         cache++;
                                         max_age = strtoul(cache, 0, 0);
                                         break;
                                  }
                                  if (*cache == 'm' && !memcmp(cache, "max-age", 7)) {
                                         cache += 7;
                                         want_equals = 1;
                                         continue;
                                  }
                         cache++;
                         }
                         if (max_age != -1) {
                                 TIM_format(TIM_real() + max_age, date);
                                 VRT_SetHdr(sp, HDR_RESP, "\010Expires:", date, vrt_magic_string_end);
                         }
                 }
        }C
        set resp.http.Cache-Control = regsuball(resp.http.Cache-Control,"max-age=[0-9]+(,)?", "");
        if ( resp.http.Cache-Control ~ "^$") {
                 unset resp.http.Cache-Control;
        }
}

Source : https://www.varnish-cache.org/trac/wiki/VCLExampleSetExpires

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre lang="" line="" escaped="" cssfile="">

(required)

(required)

Spam protection by WP Captcha-Free