Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Adds custom Cache-Control directive to control how long Varnish
- // keeps the item in cache. Copied from varnish examples site.
- // Sets the response ttl to the value specified as v-max-age in the
- // Cache-Control header. Fall back to max-age value.
- C{
- #include <errno.h>
- #include <limits.h>
- #include <stdlib.h>
- }C
- sub extended_cache_control
- {
- if (beresp.http.Cache-Control ~ "v-max-age=[0-9]+") {
- /* Copy the ttl part from original header */
- set beresp.http.X-Cache-Control-TTL = regsub(beresp.http.Cache-Control, ".*v-max-age=([0-9]+).*", "\1");
- C{
- {
- char *x_end = 0;
- const char *x_hdr_val;
- const struct gethdr_s hdr = { HDR_BERESP, "\024X-Cache-Control-TTL:" };
- x_hdr_val = VRT_GetHdr(ctx, &hdr); // number of chars
- if (x_hdr_val) {
- long x_cache_ttl = strtol(x_hdr_val, &x_end, 0);
- if (ERANGE != errno && x_end != x_hdr_val && x_cache_ttl >= 0 && x_cache_ttl < INT_MAX) {
- VRT_l_beresp_ttl(ctx, (x_cache_ttl * 1));
- }
- }
- }
- }C
- unset beresp.http.X-Cache-Control-TTL;
- } else if (beresp.http.Cache-Control ~ "max-age=[0-9]+") {
- /* Copy the ttl part from original header */
- set beresp.http.X-Cache-Control-TTL = regsub(beresp.http.Cache-Control, ".*max-age=([0-9]+).*", "\1");
- C{
- {
- char *x_end = 0;
- const char *x_hdr_val;
- const struct gethdr_s hdr = { HDR_BERESP, "\024X-Cache-Control-TTL:" };
- x_hdr_val = VRT_GetHdr(ctx, &hdr); // number of chars
- if (x_hdr_val) {
- long x_cache_ttl = strtol(x_hdr_val, &x_end, 0);
- if (ERANGE != errno && x_end != x_hdr_val && x_cache_ttl >= 0 && x_cache_ttl < INT_MAX) {
- VRT_l_beresp_ttl(ctx, (x_cache_ttl * 1));
- }
- }
- }
- }C
- unset beresp.http.X-Cache-Control-TTL;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement