{"commit":"21071cdf683a6b58722553aa9d403aaea3f73365","subject":"Rewrite port for Varnish PURGE requests","message":"Rewrite port for Varnish PURGE requests\n\nBug: T54302\nChange-Id: Ieb6a9ab49962fb76ddfd393949e53b7d1d24b9f3\n","repos":"stuartbman\/mediawiki-vagrant,stuartbman\/mediawiki-vagrant,stuartbman\/mediawiki-vagrant,HarriAlasi\/wiki3dviewer,wikimedia\/mediawiki-vagrant,HarriAlasi\/wiki3dviewer,wikimedia\/mediawiki-vagrant,stuartbman\/mediawiki-vagrant,stuartbman\/mediawiki-vagrant,HarriAlasi\/wiki3dviewer,wikimedia\/mediawiki-vagrant,HarriAlasi\/wiki3dviewer,wikimedia\/mediawiki-vagrant,wikimedia\/mediawiki-vagrant,HarriAlasi\/wiki3dviewer,stuartbman\/mediawiki-vagrant,stuartbman\/mediawiki-vagrant,HarriAlasi\/wiki3dviewer,HarriAlasi\/wiki3dviewer,wikimedia\/mediawiki-vagrant","old_file":"puppet\/modules\/varnish\/files\/default-subs.vcl","new_file":"puppet\/modules\/varnish\/files\/default-subs.vcl","new_contents":"# vcl_recv is called whenever a request is received\nsub vcl_recv {\n # Serve objects up to 2 minutes past their expiry if the backend\n # is slow to respond.\n set req.grace = 120s;\n set req.http.X-Forwarded-For = client.ip;\n\n # Since we expose varnish on the default port (6081) we need to rewrite\n # requests that are generated using the default wiki port (8080)\n # This needs to be done early because it's needed for PURGE calls\n if (req.url ~ \":8080\") {\n set req.url = regsub(req.url, \"(.*):8080\/(.*)\", \"\\1:6081\/\\2\");\n }\n\n # This uses the ACL action called \"purge\". Basically if a request to\n # PURGE the cache comes from anywhere other than localhost, ignore it.\n if (req.request == \"PURGE\") {\n if (!client.ip ~ purge) {\n error 405 \"Not allowed.\";\n }\n return(lookup);\n }\n\n # Pass any requests that Varnish does not understand straight to the backend.\n if (req.request != \"GET\" && req.request != \"HEAD\" &&\n req.request != \"PUT\" && req.request != \"POST\" &&\n req.request != \"TRACE\" && req.request != \"OPTIONS\" &&\n req.request != \"DELETE\") {\n return(pipe); \/* Non-RFC2616 or CONNECT which is weird. *\/\n }\n\n # Pass anything other than GET and HEAD directly.\n if (req.request != \"GET\" && req.request != \"HEAD\") {\n return(pass);\n }\n\n # Pretend that image requests don't have cookie\/auth, so that they get cached\n if (req.url ~ \"^\/images\/\") {\n unset req.http.Authorization;\n unset req.http.Cookie;\n }\n\n # Pass requests from logged-in users directly.\n if (req.http.Authorization || req.http.Cookie ~ \"wikiUserID=\") {\n return(pass);\n }\n\n # Pass any requests with the \"If-None-Match\" header directly.\n if (req.http.If-None-Match) {\n return(pass);\n }\n\n # Force lookup if the request is a no-cache request from the client.\n if (req.http.Cache-Control ~ \"no-cache\") {\n ban_url(req.url);\n }\n\n # Pass requests to potential non-plain reads on articles (eg. action=edit)\n if (req.url ~ \"^\/w\/index\\.php\" || req.url ~ \"^\/\\?title=\") {\n return(pass);\n }\n\n # normalize Accept-Encoding to reduce vary\n if (req.http.Accept-Encoding) {\n if (req.http.User-Agent ~ \"MSIE 6\") {\n unset req.http.Accept-Encoding;\n } elsif (req.http.Accept-Encoding ~ \"gzip\") {\n set req.http.Accept-Encoding = \"gzip\";\n } elsif (req.http.Accept-Encoding ~ \"deflate\") {\n set req.http.Accept-Encoding = \"deflate\";\n } else {\n unset req.http.Accept-Encoding;\n }\n }\n\n return(lookup);\n}\n\nsub vcl_pipe {\n # Note that only the first request to the backend will have\n # X-Forwarded-For set. If you use X-Forwarded-For and want to\n # have it set for all requests, make sure to have:\n # set req.http.connection = \"close\";\n\n # This is otherwise not necessary if you do not do any request rewriting.\n\n set req.http.connection = \"close\";\n}\n\n# Called if the cache has a copy of the page.\nsub vcl_hit {\n if (req.request == \"PURGE\") {\n ban_url(req.url);\n error 200 \"Purged\";\n }\n\n if (!obj.ttl > 0s) {\n return(pass);\n }\n}\n\n# Called if the cache does not have a copy of the page.\nsub vcl_miss {\n if (req.request == \"PURGE\") {\n error 200 \"Not in cache\";\n }\n}\n\nsub vcl_deliver {\n if (obj.hits > 0) {\n set resp.http.X-Cache = \"hit (\" + obj.hits + \")\";\n } else {\n set resp.http.X-Cache = \"miss (0)\";\n }\n}\n\n# Called after a document has been successfully retrieved from the backend.\nsub vcl_fetch {\n\n # set minimum timeouts to auto-discard stored objects\n# set beresp.prefetch = -30s;\n set beresp.grace = 120s;\n\n if (beresp.ttl < 48h) {\n set beresp.ttl = 48h;\n }\n\n if (!beresp.ttl > 0s) {\n return(hit_for_pass);\n }\n\n if (beresp.http.Set-Cookie) {\n return(hit_for_pass);\n }\n\n# if (beresp.http.Cache-Control ~ \"(private|no-cache|no-store)\")\n# {return(hit_for_pass);}\n\n if (req.http.Authorization && !beresp.http.Cache-Control ~ \"public\") {\n return(hit_for_pass);\n }\n}\n","old_contents":"# vcl_recv is called whenever a request is received\nsub vcl_recv {\n # Serve objects up to 2 minutes past their expiry if the backend\n # is slow to respond.\n set req.grace = 120s;\n set req.http.X-Forwarded-For = client.ip;\n\n # This uses the ACL action called \"purge\". Basically if a request to\n # PURGE the cache comes from anywhere other than localhost, ignore it.\n if (req.request == \"PURGE\") {\n if (!client.ip ~ purge) {\n error 405 \"Not allowed.\";\n }\n return(lookup);\n }\n\n # Pass any requests that Varnish does not understand straight to the backend.\n if (req.request != \"GET\" && req.request != \"HEAD\" &&\n req.request != \"PUT\" && req.request != \"POST\" &&\n req.request != \"TRACE\" && req.request != \"OPTIONS\" &&\n req.request != \"DELETE\") {\n return(pipe); \/* Non-RFC2616 or CONNECT which is weird. *\/\n }\n\n # Pass anything other than GET and HEAD directly.\n if (req.request != \"GET\" && req.request != \"HEAD\") {\n return(pass);\n }\n\n # Pretend that image requests don't have cookie\/auth, so that they get cached\n if (req.url ~ \"^\/images\/\") {\n unset req.http.Authorization;\n unset req.http.Cookie;\n }\n\n # Pass requests from logged-in users directly.\n if (req.http.Authorization || req.http.Cookie ~ \"wikiUserID=\") {\n return(pass);\n }\n\n # Pass any requests with the \"If-None-Match\" header directly.\n if (req.http.If-None-Match) {\n return(pass);\n }\n\n # Force lookup if the request is a no-cache request from the client.\n if (req.http.Cache-Control ~ \"no-cache\") {\n ban_url(req.url);\n }\n\n # Pass requests to potential non-plain reads on articles (eg. action=edit)\n if (req.url ~ \"^\/w\/index\\.php\" || req.url ~ \"^\/\\?title=\") {\n return(pass);\n }\n\n # normalize Accept-Encoding to reduce vary\n if (req.http.Accept-Encoding) {\n if (req.http.User-Agent ~ \"MSIE 6\") {\n unset req.http.Accept-Encoding;\n } elsif (req.http.Accept-Encoding ~ \"gzip\") {\n set req.http.Accept-Encoding = \"gzip\";\n } elsif (req.http.Accept-Encoding ~ \"deflate\") {\n set req.http.Accept-Encoding = \"deflate\";\n } else {\n unset req.http.Accept-Encoding;\n }\n }\n\n return(lookup);\n}\n\nsub vcl_pipe {\n # Note that only the first request to the backend will have\n # X-Forwarded-For set. If you use X-Forwarded-For and want to\n # have it set for all requests, make sure to have:\n # set req.http.connection = \"close\";\n\n # This is otherwise not necessary if you do not do any request rewriting.\n\n set req.http.connection = \"close\";\n}\n\n# Called if the cache has a copy of the page.\nsub vcl_hit {\n if (req.request == \"PURGE\") {\n ban_url(req.url);\n error 200 \"Purged\";\n }\n\n if (!obj.ttl > 0s) {\n return(pass);\n }\n}\n\n# Called if the cache does not have a copy of the page.\nsub vcl_miss {\n if (req.request == \"PURGE\") {\n error 200 \"Not in cache\";\n }\n}\n\nsub vcl_deliver {\n if (obj.hits > 0) {\n set resp.http.X-Cache = \"hit (\" + obj.hits + \")\";\n } else {\n set resp.http.X-Cache = \"miss (0)\";\n }\n}\n\n# Called after a document has been successfully retrieved from the backend.\nsub vcl_fetch {\n\n # set minimum timeouts to auto-discard stored objects\n# set beresp.prefetch = -30s;\n set beresp.grace = 120s;\n\n if (beresp.ttl < 48h) {\n set beresp.ttl = 48h;\n }\n\n if (!beresp.ttl > 0s) {\n return(hit_for_pass);\n }\n\n if (beresp.http.Set-Cookie) {\n return(hit_for_pass);\n }\n\n# if (beresp.http.Cache-Control ~ \"(private|no-cache|no-store)\")\n# {return(hit_for_pass);}\n\n if (req.http.Authorization && !beresp.http.Cache-Control ~ \"public\") {\n return(hit_for_pass);\n }\n}\n","returncode":0,"stderr":"","license":"mit","lang":"VCL"} {"commit":"5df22780ec5aee9214b0683b13a5585bb7e7e0e1","subject":"amend backend host inside default.vcl","message":"amend backend host inside default.vcl\n","repos":"varnish\/varnish-microservice-monitor,varnish\/zipnish,varnish\/zipnish,varnish\/zipnish,varnish\/zipnish,varnish\/varnish-microservice-monitor,varnish\/varnish-microservice-monitor,varnish\/varnish-microservice-monitor,varnish\/varnish-microservice-monitor,varnish\/zipnish","old_file":"default.vcl","new_file":"default.vcl","new_contents":"backend default {\n .host = \"i192.168.33.14\";\n .port = \"9000\";\n}\n\nsub vcl_recv {\n\treturn (pass);\n}\n\nsub vcl_backend_response {\n}\n\nsub vcl_deliver {\n}\n","old_contents":"backend default {\n .host = \"127.0.0.1\";\n .port = \"9000\";\n}\n\nsub vcl_recv {\n\treturn (pass);\n}\n\nsub vcl_backend_response {\n}\n\nsub vcl_deliver {\n}\n","returncode":0,"stderr":"","license":"bsd-2-clause","lang":"VCL"} {"commit":"4d6508800ee01c96c92fef1fa7d0fc0fde924f57","subject":"improve comment regarding HIT\/MISS detection","message":"improve comment regarding HIT\/MISS detection\n","repos":"NITEMAN\/Varnish_VCL_samps-hacks,NITEMAN\/varnish-bites","old_file":"varnish4\/drupal-base.vcl","new_file":"varnish4\/drupal-base.vcl","new_contents":"\/* Varnish 4 example config for Drupal 7 \/ Pressflow 6 & 7 *\/\n# Original source: https:\/\/github.com\/NITEMAN\/varnish-bites\/varnish4\/drupal-base.vcl\n# Copyright (c) 2015 Pedro Gonz\u00e1lez Serrano and individual contributors.\n# MIT License\n\n# Intended to be used both in simple production environments and with\n# learning\/teaching purposes.\n# Some references may not be yet updated to VCL 4.0, we use SeeV3 then.\n\n# WARNING:\n# Note that the built-in logic will be appended to our code if no return is performed before.\n# Built-in logic is included commented out right after our's for reference purposes in that cases.\n# See https:\/\/www.varnish-cache.org\/trac\/wiki\/VCLExampleDefault\n\n#######################################################################\n# Initialization: Version & imports;\n\n\/* Version statement *\/\n# Since Varnish 4.0 it's mandatory to declare VCL version on first line.\nvcl 4.0;\n\n\/* Module (VMOD) imports *\/\n# Standard module\n# See https:\/\/www.varnish-cache.org\/docs\/4.0\/reference\/vmod_std.generated.html\nimport std;\n\n# Directors module\n# See https:\/\/www.varnish-cache.org\/docs\/4.0\/reference\/vmod_directors.generated.html\n# Unused in simple configs.\n#import directors;\n\n\n#######################################################################\n# Probe, backend, ACL and subroutine definitions\n\n\/* Backend probes \/ healthchecks *\/\n# See https:\/\/www.varnish-cache.org\/docs\/4.0\/reference\/vcl.html#probes\nprobe basic {\n \/* Only test that backend's IP serves content for '\/' *\/\n # This might be a too heavy probe\n # .url = \"\/\";\n \/* Only test that backend's IP has apache working *\/\n # Nginx would fail this probe with a default config\n .request =\n \"OPTIONS * HTTP\/1.1\"\n \"Host: *\"\n \"Connection: close\";\n .interval = 10s;\n .timeout = 2s;\n .window = 8;\n .threshold = 6;\n}\n\n\/* Backend definitions.*\/\n# See https:\/\/www.varnish-cache.org\/docs\/4.0\/reference\/vcl.html#backend-definition\nbackend default {\n \/* Default backend on the same machine. WARNING: timeouts could be not big enought for certain POST request *\/\n .host = \"127.0.0.1\";\n .port = \"8008\";\n .connect_timeout = 60s;\n .first_byte_timeout = 60s;\n .between_bytes_timeout = 60s;\n .probe = basic;\n}\n\n\/* Access Control Lists *\/\n# See https:\/\/www.varnish-cache.org\/docs\/4.0\/reference\/vcl.html#access-control-list-acl\nacl purge_ban {\n \/* Simple access control list for allowing item purge for the self machine *\/\n \"127.0.0.1\"\/32; \/\/ We can use '\"localhost\";' instead\n}\nacl allowed_monitors {\n \/* Simple access control list for allowing item purge for the self machine *\/\n \"127.0.0.1\"\/32; \/\/ We can use'\"localhost\";' instead\n}\n#acl own_proxys {\n# \"127.0.0.1\"\/32; \/\/ We can use'\"localhost\";' instead\n#}\n\n\/* Custom subroutines *\/\n# See https:\/\/www.varnish-cache.org\/docs\/4.0\/reference\/vcl.html#subroutines\n#TODO# Test in Varnihs 4\n# Empty in simple configs.\n# We can name subs with no restrictions but as a task can need several chunks of code in diferent states,\n# it's a good idea to identify what main sub will call each with a suffix.\n# \/* Example 301 client redirection removing \"www\" prefix from request *\/\n# sub perm_redirections_recv {\n# if ( req.http.host ~ \"^www.*$\" ) {\n# return(synth(751, \"http:\/\/\" + regsub(req.http.host, \"^www\\.\", \"\") + req.url));\n# }\n# }\n# sub perm_redirections_synth {\n# if (resp.status == 751) {\n# \/* Get new URL from the response *\/\n# set resp.http.Location = resp.response;\n# \/* Set HTTP 301 for permanent redirect *\/\n# set resp.status = 301;\n# return (deliver);\n# }\n# }\n\n\n#######################################################################\n# Client side\n\n# vcl_recv: Called at the beginning of a request, after the complete request has been received and parsed.\n# Its purpose is to decide whether or not to serve the request, how to do it, and, if applicable, which backend to use.\n# See https:\/\/www.varnish-cache.org\/docs\/4.0\/users-guide\/vcl-built-in-subs.html#vcl-recv\nsub vcl_recv {\n \/* 0th: general bypass, general return & authorization checks *\/\n # Empty in simple configs.\n # Useful for debugging we can pipe or pass the request to default backend here to bypass completely Varnish.\n # return (pipe);\n # return (pass);\n # We can also return here a 200 Ok for network performance benchmarking.\n # return(synth(200, \"Ok\"));\n # Finally we can perform basic HTTP authentification here, by example.\n # SeeV3 http:\/\/blog.tenya.me\/blog\/2011\/12\/14\/varnish-http-authentication\/\n\n \/* 1st: Check for Varnish special requests *\/ \n # Custom response implementation example in order to check that Varnish is working properly.\n # This is usefull for automatic monitoring with monit or when Varnish is behind another proxies like HAProxy.\n if ( ( req.http.host == \"monitor.server.health\"\n || req.http.host == \"health.varnish\" )\n && client.ip ~ allowed_monitors\n && ( req.method == \"OPTIONS\" || req.method == \"GET\" )\n ) {\n return(synth(200, \"Ban added\"));\n }\n # Purge logic\n # See https:\/\/www.varnish-cache.org\/docs\/4.0\/users-guide\/purging.html#http-purging\n # SeeV3 https:\/\/www.varnish-software.com\/static\/book\/Cache_invalidation.html#removing-a-single-object\n if (req.method == \"PURGE\") {\n if (!client.ip ~ purge_ban) {\n return(synth(405, \"Not allowed.\"));\n }\n return (purge);\n }\n # Ban logic\n # See https:\/\/www.varnish-cache.org\/docs\/4.0\/users-guide\/purging.html#bans\n if (req.method == \"BAN\") {\n if (!client.ip ~ purge_ban) {\n return(synth(405, \"Not allowed.\"));\n }\n ban(\"req.http.host == \" + req.http.host +\n \"&& req.url == \" + req.url); \n return(synth(200, \"Ban added\"));\n }\n\n \/* 2nd: Do some Varnish black magic such as custom client redirections *\/\n # Empty in simple configs.\n # call perm_redirections_recv;\n # Here we can also enforce SSL when Varnish run behind some SSL termination point.\n\n \/* 3rd: Time for backend choice *\/\n # Empty in simple configs.\n\n \/* 4th: Prepare headers for the backend *\/\n # Empty in simple configs.\n # Example remove own_proxys from X-Forwarded-For\n # See https:\/\/www.varnish-cache.org\/docs\/4.0\/whats-new\/upgrading.html#x-forwarded-for-is-now-set-before-vcl-recv\n # if ( req.restarts == 0\n # && client.ip ~ own_proxys\n # && req.http.x-forwarded-for\n # ) {\n # set req.http.X-Forwarded-For = regsub(req.http.X-Forwarded-For, \",( )?\" + client.ip, \"\");\n # }\n\n \/* 5th: Bypass breakpoint 1 *\/\n # Useful for debugging we can now pipe or pass the request to backend with headers setted.\n # return (pipe);\n # return (pass);\n\n \/* 6th: Decide if we should deal with a request (mostly copied from built-in logic) *\/\n if (req.method == \"PRI\") {\n \/* We do not support SPDY or HTTP\/2.0 *\/\n return (synth(405));\n }\n if ( req.method != \"GET\"\n && req.method != \"HEAD\"\n && req.method != \"PUT\"\n && req.method != \"POST\"\n && req.method != \"TRACE\"\n && req.method != \"OPTIONS\"\n && req.method != \"DELETE\"\n ) {\n \/* Non-RFC2616 or CONNECT which is weird. *\/\n return (pipe);\n }\n if (req.method != \"GET\" && req.method != \"HEAD\") {\n \/* We only deal with GET and HEAD by default *\/\n return (pass);\n }\n if (req.http.Authorization) {\n \/* Not cacheable by default *\/\n return (pass);\n }\n\n \/* 7th: Access control for some URLs by ACL *\/\n # Empty in simple configs.\n # By example denial some URLs depending on client-ip, we'll need to define corresponding ACL 'internal'.\n # if ( req.url ~ \"^\/(cron|install)\\.php\"\n # && ! client.ip ~ internal\n # ) {\n # # Have Varnish throw the error directly.\n # return(synth(403, \"Forbidden.\"));\n # # Use a custom error page that you've defined in Drupal at the path \"404\".\n # # set req.url = \"\/403\";\n # }\n\n \/* 8th: Custom exceptions *\/\n # Host exception example:\n # if (req.http.host == \"ejemplo.exception.com\") {\n # return (pass);\n # }\n # Drupal exceptions, edit if we want to cache some AJAX\/AHAH request.\n # Add here filters for never cache URLs such as Payment Gateway's callbacks\n if (req.url ~ \"^\/status\\.php$\" ||\n req.url ~ \"^\/update\\.php$\" ||\n req.url ~ \"^\/ooyala\/ping$\" ||\n req.url ~ \"^\/admin\/build\/features\" ||\n req.url ~ \"^\/info\/.*$\" ||\n req.url ~ \"^\/flag\/.*$\" ||\n req.url ~ \"^.*\/ajax\/.*$\" ||\n req.url ~ \"^.*\/ahah\/.*$\") {\n \/* Do not cache these paths *\/\n return (pass);\n }\n # Pipe these paths directly to backend for streaming.\n if (req.url ~ \"^\/admin\/content\/backup_migrate\/export\") {\n return (pipe);\n }\n if (req.url ~ \"^\/system\/files\") {\n return (pipe);\n }\n\n \/* 9th: Serve from anonymous cahe if all backends are down *\/\n if (! std.healthy(req.backend_hint) ) {\n #TODO# Consider moving this to vcl_backend_fetch\n unset req.http.Cookie;\n #TODO# Add sick marker\n } \n\n \/* 10th: Deal with compression and the Accept-Encoding header *\/\n # Althought Varnish 3 handles gziped content itself by default, just to be sure we want to \n # remove Accept-Encoding for some compressed formats.\n # See https:\/\/www.varnish-cache.org\/docs\/4.0\/phk\/gzip.html#what-does-http-gzip-support-do\n # See https:\/\/www.varnish-cache.org\/docs\/4.0\/users-guide\/compression.html\n # See https:\/\/www.varnish-cache.org\/docs\/4.0\/reference\/varnishd.html?highlight=http_gzip_support\n # See (for older configs) https:\/\/www.varnish-cache.org\/trac\/wiki\/VCLExampleNormalizeAcceptEncoding\n if (req.http.Accept-Encoding) {\n if (req.url ~ \"\\.(jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf|mp4|flv|zip|rar)$\") {\n \/* Already compressed formats, no sense trying to compress again *\/\n unset req.http.Accept-Encoding;\n }\n }\n\n \/* 11th: Another header manipulation *\/\n # Empty in simple configs.\n # We could add here a custom header grouping User-agent families.\n\n \/* 12th: Cookie removal *\/\n # Always cache the following static file types for all users. \n # Use with care if we control certain downloads depending on cookies. \n # Be carefull also if appending .htm[l] via Drupal's clean URLs.\n if ( req.url ~ \"(?i)\\.(png|gif|jpeg|jpg|ico|swf|css|js|html|htm|gz|tgz|bz2|tbz|mp3|ogg|zip|rar|otf|ttf|eot|woff|woff2|svg|pdf)(\\?(itok=)?[a-z0-9_=\\.\\-]+)?$\"\n && req.url !~ \"\/system\/storage\/serve\"\n ) {\n unset req.http.Cookie;\n }\n # Remove all cookies that backend doesn't need to know about.\n # See https:\/\/www.varnish-cache.org\/trac\/wiki\/VCLExampleRemovingSomeCookies\n if (req.http.Cookie) {\n \/* Warning: Not a pretty solution *\/\n \/* Prefix header containing cookies with ';' *\/\n set req.http.Cookie = \";\" + req.http.Cookie;\n \/* Remove any spaces after ';' in header containing cookies *\/\n set req.http.Cookie = regsuball(req.http.Cookie, \"; +\", \";\");\n \/* Prefix cookies we want to preserve with one space *\/\n \/* 'S{1,2}ESS[a-z0-9]+' is the regular expression matching a Drupal session cookie ({1,2} added for HTTPS support) *\/\n \/* 'NO_CACHE' is usually set after a POST request to make sure issuing user see the results of his post *\/\n \/* 'OATMEAL' & 'CHOCOLATECHIP' are special cookies used by Drupal's Bakery module to provide Single Sign On *\/\n \/* Keep in mind we should add here any cookie that should reach the backend such as splahs avoiding cookies *\/\n set req.http.Cookie = regsuball(req.http.Cookie, \";(S{1,2}ESS[a-z0-9]+|NO_CACHE|OATMEAL|CHOCOLATECHIP)=\", \"; \\1=\");\n \/* Remove from the header any single Cookie not prefixed with a space until next ';' separator *\/\n set req.http.Cookie = regsuball(req.http.Cookie, \";[^ ][^;]*\", \"\");\n \/* Remove any '; ' at the start or the end of the header *\/\n set req.http.Cookie = regsuball(req.http.Cookie, \"^[; ]+|[; ]+$\", \"\");\n\n if (req.http.Cookie == \"\") {\n \/* If there are no remaining cookies, remove the cookie header. *\/\n unset req.http.Cookie;\n }\n }\n\n \/* 13th: Session cookie & special cookies bypass caching stage *\/\n # As we might want to cache some requests, hashed with its cookies, \n # we don't simply pass when some cookies remain present at this point.\n # Instead we look for request that must be passed due to the cookie header.\n if ( req.http.Cookie ~ \"SESS\"\n || req.http.Cookie ~ \"SSESS\"\n || req.http.Cookie ~ \"NO_CACHE\"\n || req.http.Cookie ~ \"OATMEAL\"\n || req.http.Cookie ~ \"CHOCOLATECHIP\"\n ) {\n return (pass);\n }\n\n \/* 14th: Bypass breakpoint 2 *\/\n # Useful for debugging we can now pipe or pass the request to backend to bypass cache.\n # return (pipe);\n # return (pass);\n\n \/* 15th: Bypass built-in logic *\/\n # We make sure no built-in logic is processed after ours returning inconditionally.\n return (hash);\n}\n\n# vcl_pipe: Called upon entering pipe mode.\n# In this mode, the request is passed on to the backend, \n# and any further data from either client or backend is passed on unaltered until either end closes the connection.\n# See https:\/\/www.varnish-cache.org\/docs\/4.0\/users-guide\/vcl-built-in-subs.html#vcl-pipe\n# sub vcl_pipe {\n# # By default Connection: close is set on all piped requests, to stop\n# # connection reuse from sending future requests directly to the\n# # (potentially) wrong backend. If you do want this to happen, you can undo\n# # it here.\n# # unset bereq.http.connection;\n# return (pipe);\n# }\n\n# vcl_pass: Called upon entering pass mode. \n# In this mode, the request is passed on to the backend, and the backend's response is passed on to the client, \n# but is not entered into the cache.\n# Subsequent requests submitted over the same client connection are handled normally.\n# See https:\/\/www.varnish-cache.org\/docs\/4.0\/users-guide\/vcl-built-in-subs.html#vcl-pass\n# sub vcl_pass {\n# return (fetch);\n# }\n\n# vcl_hash: You may call hash_data() on the data you would like to add to the hash.\n# Hash is used by Varnish to uniquely identify objects.\n# See https:\/\/www.varnish-cache.org\/docs\/4.0\/users-guide\/vcl-built-in-subs.html#vcl-hash\nsub vcl_hash {\n \/* Hash cookie data *\/\n # As requests with same URL and host can produce diferent results when issued with different cookies,\n # we need to store items hashed with the associated cookies. Note that cookies are already sanitized when we reach this point.\n if (req.http.Cookie) {\n \/* Include cookie in cache hash *\/\n hash_data(req.http.Cookie);\n }\n\n \/* Custom header hashing *\/\n # Empty in simple configs.\n # Example for caching differents object versions by device previously detected (when static content could also vary):\n # if (req.http.X-UA-Device) {\n # hash_data(req.http.X-UA-Device);\n # }\n # Example for caching diferent object versions by X-Forwarded-Proto, trying to be smart about what kind of request\n # could generate diffetent responses.\n if ( req.http.X-Forwarded-Proto\n && req.url !~ \"(?i)\\.(png|gif|jpeg|jpg|ico|gz|tgz|bz2|tbz|mp3|ogg|zip|rar|otf|ttf|eot|woff|woff2|svg|pdf)(\\?(itok=)?[a-z0-9_=\\.\\-]+)?$\") {\n hash_data(req.http.X-Forwarded-Proto);\n }\n\n \/* Continue with built-in logic *\/\n # We want built-in logic to be processed after ours so we don't call return.\n}\n# sub vcl_hash {\n# hash_data(req.url);\n# if (req.http.host) {\n# hash_data(req.http.host);\n# } else {\n# hash_data(server.ip);\n# }\n# return (lookup);\n# }\n\n# vcl_purge: Called after the purge has been executed and all its variants have been evited.\n# See https:\/\/www.varnish-cache.org\/docs\/4.0\/users-guide\/vcl-built-in-subs.html#vcl-purge\n# sub vcl_purge {\n# return (synth(200, \"Purged\"));\n# }\n\n# vcl_hit: Called after a cache lookup if the requested document was found in the cache.\n# See https:\/\/www.varnish-cache.org\/docs\/4.0\/users-guide\/vcl-built-in-subs.html#vcl-hit\nsub vcl_hit {\n if (obj.ttl >= 0s) {\n \/\/ A pure unadultered hit, deliver it\n return (deliver);\n }\n \/* Allow varnish to serve up stale content if it is responding slowly *\/\n # See https:\/\/www.varnish-cache.org\/docs\/4.0\/users-guide\/vcl-grace.html\n if (obj.ttl + 60s > 0s) {\n \/\/ Object is in grace, deliver it\n \/\/ Automatically triggers a background fetch\n return (deliver);\n }\n \/* Allow varish to serve up stale content if all backends are down *\/\n # See https:\/\/www.varnish-cache.org\/docs\/4.0\/users-guide\/vcl-grace.html\n if ( ! std.healthy(req.backend_hint)\n && obj.ttl + obj.grace > 0s\n ) {\n \/\/ Object is in grace, deliver it\n \/\/ Automatically triggers a background fetch\n return (deliver);\n }\n \/* Bypass built-in logic *\/\n # We make sure no built-in logic is processed after ours returning inconditionally.\n \/\/ fetch & deliver once we get the result\n return (fetch);\n}\n\n# vcl_miss: Called after a cache lookup if the requested document was not found in the cache.\n# Its purpose is to decide whether or not to attempt to retrieve the document from the backend, and which backend to use.\n# See https:\/\/www.varnish-cache.org\/docs\/4.0\/users-guide\/vcl-built-in-subs.html#vcl-miss\n# sub vcl_miss {\n# return (fetch);\n# }\n\n# vcl_deliver: Called before an object is delivered to the client\n# See https:\/\/www.varnish-cache.org\/docs\/4.0\/users-guide\/vcl-built-in-subs.html#vcl-deliver\nsub vcl_deliver {\n \/* Debugging headers *\/\n # Please consider the risks of showing publicly this information, we can wrap this with an ACL\n # Add whether the object is a cache hit or miss and the number of hits for the object.\n # SeeV3 https:\/\/www.varnish-cache.org\/trac\/wiki\/VCLExampleHitMissHeader#Addingaheaderindicatinghitmiss\n # In Varnish 4 the obj.hits counter behaviour has changed (see bug 1492), so\n # we use a different method: if X-Varnish contains only 1 id, we have a miss,\n # if it contains more (and therefore a space), we have a hit.\n if (resp.http.x-varnish ~ \" \") {\n set resp.http.X-Cache = \"HIT\";\n # Since in Varnish 4 the behaviour of obj.hits changed, this might not be accurate\n # See https:\/\/www.varnish-cache.org\/trac\/ticket\/1492\n set resp.http.X-Cache-Hits = obj.hits;\n } else {\n set resp.http.X-Cache = \"MISS\";\n \/* Show the results of cookie sanitization *\/\n set resp.http.X-Cookie = req.http.Cookie;\n }\n\n #TODO# Add sick marker\n\n # Restart count\n if ( req.restarts > 0) {\n set resp.http.X-Restarts = req.restarts;\n }\n\n # Add the Varnish server hostname\n set resp.http.X-Varnish-Server = server.hostname;\n # If we have setted a custom header with device family detected we can show it:\n # if (req.http.X-UA-Device) {\n # set resp.http.X-UA-Device = req.http.X-UA-Device;\n # }\n # If we have recived a custom header with the protocol in the request we can show it:\n # if (req.http.X-Forwarded-Proto) {\n # set resp.http.X-Forwarded-Proto = req.http.X-Forwarded-Proto;\n # }\n\n \/* Vary header manipulation *\/\n # Empty in simple configs.\n # By example, if we are storing & serving diferent objects depending on User-Agent header we must set the correct Vary header:\n # if (resp.http.Vary) {\n # set resp.http.Vary = resp.http.Vary + \",User-Agent\";\n # } else {\n # set resp.http.Vary = \"User-Agent\";\n # }\n\n \/* Fake headers *\/\n # Empty in simple configs\n # We can fake server headers here, by example:\n # set resp.http.Server = \"Deep thought\";\n # set resp.http.X-Powered-By = \"BOFH\";\n # Or have some fun with headers:\n # See http:\/\/www.nextthing.org\/archives\/2005\/08\/07\/fun-with-http-headers\n # See http:\/\/royal.pingdom.com\/2012\/08\/15\/fun-and-unusual-http-response-headers\/\n # set resp.http.X-Thank-You = \"for bothering to look at my HTTP headers\";\n # set resp.http.X-Answer = \"42\";\n\n \/* Continue with built-in logic *\/\n # We want built-in logic to be processed after ours so we don't call return.\n}\n# sub vcl_deliver {\n# return (deliver);\n# }\n\n# vcl_synth: Called to deliver a synthetic object. A synthetic object is generated in VCL,\n# not fetched from the backend. It is typically contructed using the synthetic() function.\n# See https:\/\/www.varnish-cache.org\/docs\/4.0\/users-guide\/vcl-built-in-subs.html#vcl-synth\n\/*\n * We can come here \"invisibly\" with the following errors: 413, 417 & 503\n *\/\nsub vcl_synth {\n \/* Do some Varnish black magic such as custom client redirections *\/\n # Empty in simple configs.\n # call perm_redirections_synth;\n\n \/* Try to restart request in case of failure *\/\n # Note that max_restarts defaults to 4\n # SeeV3 https:\/\/www.varnish-cache.org\/trac\/wiki\/VCLExampleRestarts\n if (resp.status == 503 && req.restarts < 4) {\n return(restart);\n }\n\n \/* Set common headers for synthetic responses *\/\n set resp.http.Content-Type = \"text\/html; charset=utf-8\";\n\n \/* HTTP Authentification client request *\/\n # Empty in simple configs. SeeV3 http:\/\/blog.tenya.me\/blog\/2011\/12\/14\/varnish-http-authentication\/\n\n \/* Error page & refresh \/ redirections *\/\n # We have plenty of choices when we have to serve an error to the client, \n # from the default error page to javascript black magic or plain redirections.\n # Adding some external statistic javascript to track failures served to clients is strongly suggested.\n # We can't use external resources on synthetic content, everything must be inlined.\n # If we need to include images we can embed them in base64 encoding.\n # Here is the default error page for Varnish 4 (not so pretty)\n # We're using error 200 for monitoring puposes which should not be retried client side *\/\n if ( resp.status != 200) {\n set resp.http.Retry-After = \"5\";\n }\n\n ## Example custom 403 error page.\n #if (resp.status == 403) {\n # synthetic(std.fileread(\"\/403.html\"));\n # return(deliver);\n #}\n \n # Consider add some analytics stuff to trace accesses\n synthetic( {\"\n\n
\n\"} + resp.reason + {\"<\/p>\n
XID: \"} + req.xid + {\"<\/p>\n
Varnish cache server<\/p>\n <\/body>\n<\/html>\n\"} );\n\n \/* Bypass built-in logic *\/\n # We make sure no built-in logic is processed after ours returning inconditionally.\n return (deliver);\n}\n\n#######################################################################\n# Backend Fetch\n\n# vcl_backend_fetch: Called before sending the backend request. In this subroutine you typically alter the request before it gets to the backend.\n# See https:\/\/www.varnish-cache.org\/docs\/4.0\/users-guide\/vcl-built-in-subs.html#vcl-backend-fetch\n# sub vcl_backend_fetch {\n# return (fetch);\n# }\n\n# vcl_backend_response: Called after the response headers has been successfully retrieved from the backend.\n# See https:\/\/www.varnish-cache.org\/docs\/4.0\/users-guide\/vcl-built-in-subs.html#vcl-backend-response\nsub vcl_backend_response {\n \/* Caching exceptions *\/\n # Varnish will cache objects with response codes: 200, 203, 300, 301, 302, 307, 404 & 410.\n # SeeV3 https:\/\/www.varnish-software.com\/static\/book\/VCL_Basics.html#the-initial-value-of-beresp-ttl\n # Drupal's Imagecache module can return a 307 redirection to the requested url itself and, depending on Drupal's cache settings,\n # this could lead to a redirection loop being cached for a long time but also we want Varnish to shield a little the backend.\n # See http:\/\/drupal.org\/node\/1248010\n # See http:\/\/drupal.org\/node\/310656\n if (beresp.status == 307 &&\n #TODO# verify that this work better than 'bereq.url ~ \"imagecache\"' *\/\n beresp.http.Location == bereq.url &&\n beresp.ttl > 5s) {\n set beresp.ttl = 5s;\n set beresp.http.cache-control = \"max-age=5\";\n }\n\n \/* Request retrial *\/\n if ( beresp.status == 500\n || beresp.status == 503\n ) {\n #TODO# consider not restarting POST requests as seenV3 on https:\/\/www.varnish-cache.org\/trac\/wiki\/VCLExampleSaintMode\n return (retry);\n }\n\n \/* Enable grace mode. Related with vcl_hit *\/\n # See https:\/\/www.varnish-cache.org\/docs\/4.0\/users-guide\/vcl-grace.html\n set beresp.grace = 1h;\n\n \/* Strip cookies from the following static file types for all users. Related with our 12th stage on vcl_recv *\/\n if (bereq.url ~ \"(?i)\\.(png|gif|jpeg|jpg|ico|swf|css|js|html|htm|gz|tgz|bz2|tbz|mp3|ogg|zip|rar|otf|ttf|eot|woff|woff2|svg|pdf)(\\?(itok=)?[a-z0-9_=\\.\\-]+)?$\") {\n unset beresp.http.set-cookie;\n }\n\n \/* Gzip response *\/\n # Empty in simple configs\n # Use Varnish to Gzip respone, if suitable, before storing it on cache\n # See https:\/\/www.varnish-cache.org\/docs\/4.0\/users-guide\/compression.html\n # See https:\/\/www.varnish-cache.org\/docs\/4.0\/phk\/gzip.html\n if ( ! beresp.http.Content-Encoding\n && ( beresp.http.content-type ~ \"text\"\n || beresp.http.content-type ~ \"application\/x-javascript\"\n || beresp.http.content-type ~ \"application\/javascript\"\n || beresp.http.content-type ~ \"application\/rss+xml\"\n || beresp.http.content-type ~ \"application\/xml\"\n || beresp.http.content-type ~ \"Application\/JSON\")\n ) {\n set beresp.do_gzip = true;\n }\n\n \/* Debugging headers *\/\n # Please consider the risks of showing publicly this information, we can wrap this with an ACL\n # We can add the name of the backend that has processed the request:\n # set beresp.http.X-Backend = beresp.backend.name;\n # We can use a header to tell if the object was gziped by Varnish\n # if (beresp.do_gzip) {\n # set beresp.http.X-Varnish-Gzipped = \"yes\";\n # } else {\n # set beresp.http.X-Varnish-Gizipped = \"no\";\n # }\n # We can also add headers informing whether the object is cacheable or not and why.\n # https:\/\/www.varnish-cache.org\/trac\/wiki\/VCLExampleHitMissHeader#Varnish3.0\n if (beresp.ttl <= 0s) {\n \/* Varnish determined the object was not cacheable *\/\n set beresp.http.X-Cacheable = \"NO:Not Cacheable\";\n } elsif (bereq.http.Cookie ~ \"(SESS|SSESS|NO_CACHE|OATMEAL|CHOCOLATECHIP)\") {\n \/* We don't wish to cache content for logged in users or with certain cookies. Related with our 9th stage on vcl_recv *\/\n set beresp.http.X-Cacheable = \"NO:Cookies\";\n # return(hit_for_pass);\n } elsif (beresp.http.Cache-Control ~ \"private\") {\n \/* We are respecting the Cache-Control=private header from the backend *\/\n set beresp.http.X-Cacheable = \"NO:Cache-Control=private\";\n # return(hit_for_pass);\n } else {\n \/* Varnish determined the object was cacheable *\/\n set beresp.http.X-Cacheable = \"YES\";\n }\n\n \/* Further header manipulation *\/\n # Empty in simple configs.\n # We can also unset some headers to prevent information disclosure and save some cache space\n # unset beresp.http.Server;\n # unset beresp.http.X-Powered-By;\n # Retry count\n if ( bereq.retries > 0) {\n set beresp.http.X-Retries = bereq.retries;\n }\n\n \/* Continue with built-in logic *\/\n # We want built-in logic to be processed after ours so we don't call return.\n}\n# sub vcl_backend_response {\n# if (beresp.ttl <= 0s ||\n# beresp.http.Set-Cookie ||\n# beresp.http.Surrogate-control ~ \"no-store\" ||\n# (!beresp.http.Surrogate-Control &&\n# beresp.http.Cache-Control ~ \"no-cache|no-store|private\") ||\n# beresp.http.Vary == \"*\") {\n# \/*\n# * Mark as \"Hit-For-Pass\" for the next 2 minutes\n# *\/\n# set beresp.ttl = 120s;\n# set beresp.uncacheable = true;\n# }\n# return (deliver);\n# }\n\n# vcl_backend_error: This subroutine is called if we fail the backend fetch.\n# See https:\/\/www.varnish-cache.org\/docs\/4.0\/users-guide\/vcl-built-in-subs.html#vcl-backend-error\nsub vcl_backend_error {\n\n \/* Try to restart request in case of failure *\/\n #TODO# Confirm max_retries default value\n # SeeV3 https:\/\/www.varnish-cache.org\/trac\/wiki\/VCLExampleRestarts\n if (bereq.retries < 4) {\n return (retry);\n }\n\n \/* Debugging headers *\/\n # Please consider the risks of showing publicly this information, we can wrap this with an ACL\n # Retry count\n if ( bereq.retries > 0) {\n set beresp.http.X-Retries = bereq.retries;\n }\n\n set beresp.http.Content-Type = \"text\/html; charset=utf-8\";\n set beresp.http.Retry-After = \"5\";\n synthetic( {\"\n\n
\n\"} + beresp.reason + {\"<\/p>\n
XID: \"} + bereq.xid + {\"<\/p>\n
Varnish cache server<\/p>\n <\/body>\n<\/html>\n\"} );\n\n \/* Bypass built-in logic *\/\n # We make sure no built-in logic is processed after ours returning at this point.\n return (deliver);\n}\n\n#######################################################################\n# Housekeeping\n\n# vcl_init: Called when VCL is loaded, before any requests pass through it. Typically used to initialize VMODs.\n# See https:\/\/www.varnish-cache.org\/docs\/4.0\/users-guide\/vcl-built-in-subs.html#vcl-init\n# Here is where you should declare your directors now.\n# See https:\/\/www.varnish-cache.org\/docs\/4.0\/reference\/vmod_directors.generated.html\n# See https:\/\/www.varnish-cache.org\/docs\/4.0\/users-guide\/vcl-backends.html#directors\n# Empty in simple configs\n# sub vcl_init {\n# return (ok);\n# }\n\n# vcl_fini: Called when VCL is discarded only after all requests have exited the VCL. Typically used to clean up VMODs.\n# See https:\/\/www.varnish-cache.org\/docs\/4.0\/users-guide\/vcl-built-in-subs.html#vcl-fini\n# sub vcl_fini {\n# return (ok);\n# }\n\n","old_contents":"\/* Varnish 4 example config for Drupal 7 \/ Pressflow 6 & 7 *\/\n# Original source: https:\/\/github.com\/NITEMAN\/varnish-bites\/varnish4\/drupal-base.vcl\n# Copyright (c) 2015 Pedro Gonz\u00e1lez Serrano and individual contributors.\n# MIT License\n\n# Intended to be used both in simple production environments and with\n# learning\/teaching purposes.\n# Some references may not be yet updated to VCL 4.0, we use SeeV3 then.\n\n# WARNING:\n# Note that the built-in logic will be appended to our code if no return is performed before.\n# Built-in logic is included commented out right after our's for reference purposes in that cases.\n# See https:\/\/www.varnish-cache.org\/trac\/wiki\/VCLExampleDefault\n\n#######################################################################\n# Initialization: Version & imports;\n\n\/* Version statement *\/\n# Since Varnish 4.0 it's mandatory to declare VCL version on first line.\nvcl 4.0;\n\n\/* Module (VMOD) imports *\/\n# Standard module\n# See https:\/\/www.varnish-cache.org\/docs\/4.0\/reference\/vmod_std.generated.html\nimport std;\n\n# Directors module\n# See https:\/\/www.varnish-cache.org\/docs\/4.0\/reference\/vmod_directors.generated.html\n# Unused in simple configs.\n#import directors;\n\n\n#######################################################################\n# Probe, backend, ACL and subroutine definitions\n\n\/* Backend probes \/ healthchecks *\/\n# See https:\/\/www.varnish-cache.org\/docs\/4.0\/reference\/vcl.html#probes\nprobe basic {\n \/* Only test that backend's IP serves content for '\/' *\/\n # This might be a too heavy probe\n # .url = \"\/\";\n \/* Only test that backend's IP has apache working *\/\n # Nginx would fail this probe with a default config\n .request =\n \"OPTIONS * HTTP\/1.1\"\n \"Host: *\"\n \"Connection: close\";\n .interval = 10s;\n .timeout = 2s;\n .window = 8;\n .threshold = 6;\n}\n\n\/* Backend definitions.*\/\n# See https:\/\/www.varnish-cache.org\/docs\/4.0\/reference\/vcl.html#backend-definition\nbackend default {\n \/* Default backend on the same machine. WARNING: timeouts could be not big enought for certain POST request *\/\n .host = \"127.0.0.1\";\n .port = \"8008\";\n .connect_timeout = 60s;\n .first_byte_timeout = 60s;\n .between_bytes_timeout = 60s;\n .probe = basic;\n}\n\n\/* Access Control Lists *\/\n# See https:\/\/www.varnish-cache.org\/docs\/4.0\/reference\/vcl.html#access-control-list-acl\nacl purge_ban {\n \/* Simple access control list for allowing item purge for the self machine *\/\n \"127.0.0.1\"\/32; \/\/ We can use '\"localhost\";' instead\n}\nacl allowed_monitors {\n \/* Simple access control list for allowing item purge for the self machine *\/\n \"127.0.0.1\"\/32; \/\/ We can use'\"localhost\";' instead\n}\n#acl own_proxys {\n# \"127.0.0.1\"\/32; \/\/ We can use'\"localhost\";' instead\n#}\n\n\/* Custom subroutines *\/\n# See https:\/\/www.varnish-cache.org\/docs\/4.0\/reference\/vcl.html#subroutines\n#TODO# Test in Varnihs 4\n# Empty in simple configs.\n# We can name subs with no restrictions but as a task can need several chunks of code in diferent states,\n# it's a good idea to identify what main sub will call each with a suffix.\n# \/* Example 301 client redirection removing \"www\" prefix from request *\/\n# sub perm_redirections_recv {\n# if ( req.http.host ~ \"^www.*$\" ) {\n# return(synth(751, \"http:\/\/\" + regsub(req.http.host, \"^www\\.\", \"\") + req.url));\n# }\n# }\n# sub perm_redirections_synth {\n# if (resp.status == 751) {\n# \/* Get new URL from the response *\/\n# set resp.http.Location = resp.response;\n# \/* Set HTTP 301 for permanent redirect *\/\n# set resp.status = 301;\n# return (deliver);\n# }\n# }\n\n\n#######################################################################\n# Client side\n\n# vcl_recv: Called at the beginning of a request, after the complete request has been received and parsed.\n# Its purpose is to decide whether or not to serve the request, how to do it, and, if applicable, which backend to use.\n# See https:\/\/www.varnish-cache.org\/docs\/4.0\/users-guide\/vcl-built-in-subs.html#vcl-recv\nsub vcl_recv {\n \/* 0th: general bypass, general return & authorization checks *\/\n # Empty in simple configs.\n # Useful for debugging we can pipe or pass the request to default backend here to bypass completely Varnish.\n # return (pipe);\n # return (pass);\n # We can also return here a 200 Ok for network performance benchmarking.\n # return(synth(200, \"Ok\"));\n # Finally we can perform basic HTTP authentification here, by example.\n # SeeV3 http:\/\/blog.tenya.me\/blog\/2011\/12\/14\/varnish-http-authentication\/\n\n \/* 1st: Check for Varnish special requests *\/ \n # Custom response implementation example in order to check that Varnish is working properly.\n # This is usefull for automatic monitoring with monit or when Varnish is behind another proxies like HAProxy.\n if ( ( req.http.host == \"monitor.server.health\"\n || req.http.host == \"health.varnish\" )\n && client.ip ~ allowed_monitors\n && ( req.method == \"OPTIONS\" || req.method == \"GET\" )\n ) {\n return(synth(200, \"Ban added\"));\n }\n # Purge logic\n # See https:\/\/www.varnish-cache.org\/docs\/4.0\/users-guide\/purging.html#http-purging\n # SeeV3 https:\/\/www.varnish-software.com\/static\/book\/Cache_invalidation.html#removing-a-single-object\n if (req.method == \"PURGE\") {\n if (!client.ip ~ purge_ban) {\n return(synth(405, \"Not allowed.\"));\n }\n return (purge);\n }\n # Ban logic\n # See https:\/\/www.varnish-cache.org\/docs\/4.0\/users-guide\/purging.html#bans\n if (req.method == \"BAN\") {\n if (!client.ip ~ purge_ban) {\n return(synth(405, \"Not allowed.\"));\n }\n ban(\"req.http.host == \" + req.http.host +\n \"&& req.url == \" + req.url); \n return(synth(200, \"Ban added\"));\n }\n\n \/* 2nd: Do some Varnish black magic such as custom client redirections *\/\n # Empty in simple configs.\n # call perm_redirections_recv;\n # Here we can also enforce SSL when Varnish run behind some SSL termination point.\n\n \/* 3rd: Time for backend choice *\/\n # Empty in simple configs.\n\n \/* 4th: Prepare headers for the backend *\/\n # Empty in simple configs.\n # Example remove own_proxys from X-Forwarded-For\n # See https:\/\/www.varnish-cache.org\/docs\/4.0\/whats-new\/upgrading.html#x-forwarded-for-is-now-set-before-vcl-recv\n # if ( req.restarts == 0\n # && client.ip ~ own_proxys\n # && req.http.x-forwarded-for\n # ) {\n # set req.http.X-Forwarded-For = regsub(req.http.X-Forwarded-For, \",( )?\" + client.ip, \"\");\n # }\n\n \/* 5th: Bypass breakpoint 1 *\/\n # Useful for debugging we can now pipe or pass the request to backend with headers setted.\n # return (pipe);\n # return (pass);\n\n \/* 6th: Decide if we should deal with a request (mostly copied from built-in logic) *\/\n if (req.method == \"PRI\") {\n \/* We do not support SPDY or HTTP\/2.0 *\/\n return (synth(405));\n }\n if ( req.method != \"GET\"\n && req.method != \"HEAD\"\n && req.method != \"PUT\"\n && req.method != \"POST\"\n && req.method != \"TRACE\"\n && req.method != \"OPTIONS\"\n && req.method != \"DELETE\"\n ) {\n \/* Non-RFC2616 or CONNECT which is weird. *\/\n return (pipe);\n }\n if (req.method != \"GET\" && req.method != \"HEAD\") {\n \/* We only deal with GET and HEAD by default *\/\n return (pass);\n }\n if (req.http.Authorization) {\n \/* Not cacheable by default *\/\n return (pass);\n }\n\n \/* 7th: Access control for some URLs by ACL *\/\n # Empty in simple configs.\n # By example denial some URLs depending on client-ip, we'll need to define corresponding ACL 'internal'.\n # if ( req.url ~ \"^\/(cron|install)\\.php\"\n # && ! client.ip ~ internal\n # ) {\n # # Have Varnish throw the error directly.\n # return(synth(403, \"Forbidden.\"));\n # # Use a custom error page that you've defined in Drupal at the path \"404\".\n # # set req.url = \"\/403\";\n # }\n\n \/* 8th: Custom exceptions *\/\n # Host exception example:\n # if (req.http.host == \"ejemplo.exception.com\") {\n # return (pass);\n # }\n # Drupal exceptions, edit if we want to cache some AJAX\/AHAH request.\n # Add here filters for never cache URLs such as Payment Gateway's callbacks\n if (req.url ~ \"^\/status\\.php$\" ||\n req.url ~ \"^\/update\\.php$\" ||\n req.url ~ \"^\/ooyala\/ping$\" ||\n req.url ~ \"^\/admin\/build\/features\" ||\n req.url ~ \"^\/info\/.*$\" ||\n req.url ~ \"^\/flag\/.*$\" ||\n req.url ~ \"^.*\/ajax\/.*$\" ||\n req.url ~ \"^.*\/ahah\/.*$\") {\n \/* Do not cache these paths *\/\n return (pass);\n }\n # Pipe these paths directly to backend for streaming.\n if (req.url ~ \"^\/admin\/content\/backup_migrate\/export\") {\n return (pipe);\n }\n if (req.url ~ \"^\/system\/files\") {\n return (pipe);\n }\n\n \/* 9th: Serve from anonymous cahe if all backends are down *\/\n if (! std.healthy(req.backend_hint) ) {\n #TODO# Consider moving this to vcl_backend_fetch\n unset req.http.Cookie;\n #TODO# Add sick marker\n } \n\n \/* 10th: Deal with compression and the Accept-Encoding header *\/\n # Althought Varnish 3 handles gziped content itself by default, just to be sure we want to \n # remove Accept-Encoding for some compressed formats.\n # See https:\/\/www.varnish-cache.org\/docs\/4.0\/phk\/gzip.html#what-does-http-gzip-support-do\n # See https:\/\/www.varnish-cache.org\/docs\/4.0\/users-guide\/compression.html\n # See https:\/\/www.varnish-cache.org\/docs\/4.0\/reference\/varnishd.html?highlight=http_gzip_support\n # See (for older configs) https:\/\/www.varnish-cache.org\/trac\/wiki\/VCLExampleNormalizeAcceptEncoding\n if (req.http.Accept-Encoding) {\n if (req.url ~ \"\\.(jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf|mp4|flv|zip|rar)$\") {\n \/* Already compressed formats, no sense trying to compress again *\/\n unset req.http.Accept-Encoding;\n }\n }\n\n \/* 11th: Another header manipulation *\/\n # Empty in simple configs.\n # We could add here a custom header grouping User-agent families.\n\n \/* 12th: Cookie removal *\/\n # Always cache the following static file types for all users. \n # Use with care if we control certain downloads depending on cookies. \n # Be carefull also if appending .htm[l] via Drupal's clean URLs.\n if ( req.url ~ \"(?i)\\.(png|gif|jpeg|jpg|ico|swf|css|js|html|htm|gz|tgz|bz2|tbz|mp3|ogg|zip|rar|otf|ttf|eot|woff|woff2|svg|pdf)(\\?(itok=)?[a-z0-9_=\\.\\-]+)?$\"\n && req.url !~ \"\/system\/storage\/serve\"\n ) {\n unset req.http.Cookie;\n }\n # Remove all cookies that backend doesn't need to know about.\n # See https:\/\/www.varnish-cache.org\/trac\/wiki\/VCLExampleRemovingSomeCookies\n if (req.http.Cookie) {\n \/* Warning: Not a pretty solution *\/\n \/* Prefix header containing cookies with ';' *\/\n set req.http.Cookie = \";\" + req.http.Cookie;\n \/* Remove any spaces after ';' in header containing cookies *\/\n set req.http.Cookie = regsuball(req.http.Cookie, \"; +\", \";\");\n \/* Prefix cookies we want to preserve with one space *\/\n \/* 'S{1,2}ESS[a-z0-9]+' is the regular expression matching a Drupal session cookie ({1,2} added for HTTPS support) *\/\n \/* 'NO_CACHE' is usually set after a POST request to make sure issuing user see the results of his post *\/\n \/* 'OATMEAL' & 'CHOCOLATECHIP' are special cookies used by Drupal's Bakery module to provide Single Sign On *\/\n \/* Keep in mind we should add here any cookie that should reach the backend such as splahs avoiding cookies *\/\n set req.http.Cookie = regsuball(req.http.Cookie, \";(S{1,2}ESS[a-z0-9]+|NO_CACHE|OATMEAL|CHOCOLATECHIP)=\", \"; \\1=\");\n \/* Remove from the header any single Cookie not prefixed with a space until next ';' separator *\/\n set req.http.Cookie = regsuball(req.http.Cookie, \";[^ ][^;]*\", \"\");\n \/* Remove any '; ' at the start or the end of the header *\/\n set req.http.Cookie = regsuball(req.http.Cookie, \"^[; ]+|[; ]+$\", \"\");\n\n if (req.http.Cookie == \"\") {\n \/* If there are no remaining cookies, remove the cookie header. *\/\n unset req.http.Cookie;\n }\n }\n\n \/* 13th: Session cookie & special cookies bypass caching stage *\/\n # As we might want to cache some requests, hashed with its cookies, \n # we don't simply pass when some cookies remain present at this point.\n # Instead we look for request that must be passed due to the cookie header.\n if ( req.http.Cookie ~ \"SESS\"\n || req.http.Cookie ~ \"SSESS\"\n || req.http.Cookie ~ \"NO_CACHE\"\n || req.http.Cookie ~ \"OATMEAL\"\n || req.http.Cookie ~ \"CHOCOLATECHIP\"\n ) {\n return (pass);\n }\n\n \/* 14th: Bypass breakpoint 2 *\/\n # Useful for debugging we can now pipe or pass the request to backend to bypass cache.\n # return (pipe);\n # return (pass);\n\n \/* 15th: Bypass built-in logic *\/\n # We make sure no built-in logic is processed after ours returning inconditionally.\n return (hash);\n}\n\n# vcl_pipe: Called upon entering pipe mode.\n# In this mode, the request is passed on to the backend, \n# and any further data from either client or backend is passed on unaltered until either end closes the connection.\n# See https:\/\/www.varnish-cache.org\/docs\/4.0\/users-guide\/vcl-built-in-subs.html#vcl-pipe\n# sub vcl_pipe {\n# # By default Connection: close is set on all piped requests, to stop\n# # connection reuse from sending future requests directly to the\n# # (potentially) wrong backend. If you do want this to happen, you can undo\n# # it here.\n# # unset bereq.http.connection;\n# return (pipe);\n# }\n\n# vcl_pass: Called upon entering pass mode. \n# In this mode, the request is passed on to the backend, and the backend's response is passed on to the client, \n# but is not entered into the cache.\n# Subsequent requests submitted over the same client connection are handled normally.\n# See https:\/\/www.varnish-cache.org\/docs\/4.0\/users-guide\/vcl-built-in-subs.html#vcl-pass\n# sub vcl_pass {\n# return (fetch);\n# }\n\n# vcl_hash: You may call hash_data() on the data you would like to add to the hash.\n# Hash is used by Varnish to uniquely identify objects.\n# See https:\/\/www.varnish-cache.org\/docs\/4.0\/users-guide\/vcl-built-in-subs.html#vcl-hash\nsub vcl_hash {\n \/* Hash cookie data *\/\n # As requests with same URL and host can produce diferent results when issued with different cookies,\n # we need to store items hashed with the associated cookies. Note that cookies are already sanitized when we reach this point.\n if (req.http.Cookie) {\n \/* Include cookie in cache hash *\/\n hash_data(req.http.Cookie);\n }\n\n \/* Custom header hashing *\/\n # Empty in simple configs.\n # Example for caching differents object versions by device previously detected (when static content could also vary):\n # if (req.http.X-UA-Device) {\n # hash_data(req.http.X-UA-Device);\n # }\n # Example for caching diferent object versions by X-Forwarded-Proto, trying to be smart about what kind of request\n # could generate diffetent responses.\n if ( req.http.X-Forwarded-Proto\n && req.url !~ \"(?i)\\.(png|gif|jpeg|jpg|ico|gz|tgz|bz2|tbz|mp3|ogg|zip|rar|otf|ttf|eot|woff|woff2|svg|pdf)(\\?(itok=)?[a-z0-9_=\\.\\-]+)?$\") {\n hash_data(req.http.X-Forwarded-Proto);\n }\n\n \/* Continue with built-in logic *\/\n # We want built-in logic to be processed after ours so we don't call return.\n}\n# sub vcl_hash {\n# hash_data(req.url);\n# if (req.http.host) {\n# hash_data(req.http.host);\n# } else {\n# hash_data(server.ip);\n# }\n# return (lookup);\n# }\n\n# vcl_purge: Called after the purge has been executed and all its variants have been evited.\n# See https:\/\/www.varnish-cache.org\/docs\/4.0\/users-guide\/vcl-built-in-subs.html#vcl-purge\n# sub vcl_purge {\n# return (synth(200, \"Purged\"));\n# }\n\n# vcl_hit: Called after a cache lookup if the requested document was found in the cache.\n# See https:\/\/www.varnish-cache.org\/docs\/4.0\/users-guide\/vcl-built-in-subs.html#vcl-hit\nsub vcl_hit {\n if (obj.ttl >= 0s) {\n \/\/ A pure unadultered hit, deliver it\n return (deliver);\n }\n \/* Allow varnish to serve up stale content if it is responding slowly *\/\n # See https:\/\/www.varnish-cache.org\/docs\/4.0\/users-guide\/vcl-grace.html\n if (obj.ttl + 60s > 0s) {\n \/\/ Object is in grace, deliver it\n \/\/ Automatically triggers a background fetch\n return (deliver);\n }\n \/* Allow varish to serve up stale content if all backends are down *\/\n # See https:\/\/www.varnish-cache.org\/docs\/4.0\/users-guide\/vcl-grace.html\n if ( ! std.healthy(req.backend_hint)\n && obj.ttl + obj.grace > 0s\n ) {\n \/\/ Object is in grace, deliver it\n \/\/ Automatically triggers a background fetch\n return (deliver);\n }\n \/* Bypass built-in logic *\/\n # We make sure no built-in logic is processed after ours returning inconditionally.\n \/\/ fetch & deliver once we get the result\n return (fetch);\n}\n\n# vcl_miss: Called after a cache lookup if the requested document was not found in the cache.\n# Its purpose is to decide whether or not to attempt to retrieve the document from the backend, and which backend to use.\n# See https:\/\/www.varnish-cache.org\/docs\/4.0\/users-guide\/vcl-built-in-subs.html#vcl-miss\n# sub vcl_miss {\n# return (fetch);\n# }\n\n# vcl_deliver: Called before an object is delivered to the client\n# See https:\/\/www.varnish-cache.org\/docs\/4.0\/users-guide\/vcl-built-in-subs.html#vcl-deliver\nsub vcl_deliver {\n \/* Debugging headers *\/\n # Please consider the risks of showing publicly this information, we can wrap this with an ACL\n # In Varnish 4 the obj.hits counter behaviour has changed, so we use a\n # different method: if X-Varnish contains only 1 id, we have a miss, if it\n # contains more (and therefore a space), we have a hit.\n if (resp.http.x-varnish ~ \" \") {\n set resp.http.X-Cache = \"HIT\";\n set resp.http.X-Cache-Hits = obj.hits;\n } else {\n set resp.http.X-Cache = \"MISS\";\n \/* Show the results of cookie sanitization *\/\n set resp.http.X-Cookie = req.http.Cookie;\n }\n \n\n #TODO# Add sick marker\n # Restart count\n if ( req.restarts > 0) {\n set resp.http.X-Restarts = req.restarts;\n }\n\n # Add the Varnish server hostname\n set resp.http.X-Varnish-Server = server.hostname;\n # If we have setted a custom header with device family detected we can show it:\n # if (req.http.X-UA-Device) {\n # set resp.http.X-UA-Device = req.http.X-UA-Device;\n # }\n # If we have recived a custom header with the protocol in the request we can show it:\n # if (req.http.X-Forwarded-Proto) {\n # set resp.http.X-Forwarded-Proto = req.http.X-Forwarded-Proto;\n # }\n\n \/* Vary header manipulation *\/\n # Empty in simple configs.\n # By example, if we are storing & serving diferent objects depending on User-Agent header we must set the correct Vary header:\n # if (resp.http.Vary) {\n # set resp.http.Vary = resp.http.Vary + \",User-Agent\";\n # } else {\n # set resp.http.Vary = \"User-Agent\";\n # }\n\n \/* Fake headers *\/\n # Empty in simple configs\n # We can fake server headers here, by example:\n # set resp.http.Server = \"Deep thought\";\n # set resp.http.X-Powered-By = \"BOFH\";\n # Or have some fun with headers:\n # See http:\/\/www.nextthing.org\/archives\/2005\/08\/07\/fun-with-http-headers\n # See http:\/\/royal.pingdom.com\/2012\/08\/15\/fun-and-unusual-http-response-headers\/\n # set resp.http.X-Thank-You = \"for bothering to look at my HTTP headers\";\n # set resp.http.X-Answer = \"42\";\n\n \/* Continue with built-in logic *\/\n # We want built-in logic to be processed after ours so we don't call return.\n}\n# sub vcl_deliver {\n# return (deliver);\n# }\n\n# vcl_synth: Called to deliver a synthetic object. A synthetic object is generated in VCL,\n# not fetched from the backend. It is typically contructed using the synthetic() function.\n# See https:\/\/www.varnish-cache.org\/docs\/4.0\/users-guide\/vcl-built-in-subs.html#vcl-synth\n\/*\n * We can come here \"invisibly\" with the following errors: 413, 417 & 503\n *\/\nsub vcl_synth {\n \/* Do some Varnish black magic such as custom client redirections *\/\n # Empty in simple configs.\n # call perm_redirections_synth;\n\n \/* Try to restart request in case of failure *\/\n # Note that max_restarts defaults to 4\n # SeeV3 https:\/\/www.varnish-cache.org\/trac\/wiki\/VCLExampleRestarts\n if (resp.status == 503 && req.restarts < 4) {\n return(restart);\n }\n\n \/* Set common headers for synthetic responses *\/\n set resp.http.Content-Type = \"text\/html; charset=utf-8\";\n\n \/* HTTP Authentification client request *\/\n # Empty in simple configs. SeeV3 http:\/\/blog.tenya.me\/blog\/2011\/12\/14\/varnish-http-authentication\/\n\n \/* Error page & refresh \/ redirections *\/\n # We have plenty of choices when we have to serve an error to the client, \n # from the default error page to javascript black magic or plain redirections.\n # Adding some external statistic javascript to track failures served to clients is strongly suggested.\n # We can't use external resources on synthetic content, everything must be inlined.\n # If we need to include images we can embed them in base64 encoding.\n # Here is the default error page for Varnish 4 (not so pretty)\n # We're using error 200 for monitoring puposes which should not be retried client side *\/\n if ( resp.status != 200) {\n set resp.http.Retry-After = \"5\";\n }\n\n ## Example custom 403 error page.\n #if (resp.status == 403) {\n # synthetic(std.fileread(\"\/403.html\"));\n # return(deliver);\n #}\n \n # Consider add some analytics stuff to trace accesses\n synthetic( {\"\n\n
\n\"} + resp.reason + {\"<\/p>\n
XID: \"} + req.xid + {\"<\/p>\n
Varnish cache server<\/p>\n <\/body>\n<\/html>\n\"} );\n\n \/* Bypass built-in logic *\/\n # We make sure no built-in logic is processed after ours returning inconditionally.\n return (deliver);\n}\n\n#######################################################################\n# Backend Fetch\n\n# vcl_backend_fetch: Called before sending the backend request. In this subroutine you typically alter the request before it gets to the backend.\n# See https:\/\/www.varnish-cache.org\/docs\/4.0\/users-guide\/vcl-built-in-subs.html#vcl-backend-fetch\n# sub vcl_backend_fetch {\n# return (fetch);\n# }\n\n# vcl_backend_response: Called after the response headers has been successfully retrieved from the backend.\n# See https:\/\/www.varnish-cache.org\/docs\/4.0\/users-guide\/vcl-built-in-subs.html#vcl-backend-response\nsub vcl_backend_response {\n \/* Caching exceptions *\/\n # Varnish will cache objects with response codes: 200, 203, 300, 301, 302, 307, 404 & 410.\n # SeeV3 https:\/\/www.varnish-software.com\/static\/book\/VCL_Basics.html#the-initial-value-of-beresp-ttl\n # Drupal's Imagecache module can return a 307 redirection to the requested url itself and, depending on Drupal's cache settings,\n # this could lead to a redirection loop being cached for a long time but also we want Varnish to shield a little the backend.\n # See http:\/\/drupal.org\/node\/1248010\n # See http:\/\/drupal.org\/node\/310656\n if (beresp.status == 307 &&\n #TODO# verify that this work better than 'bereq.url ~ \"imagecache\"' *\/\n beresp.http.Location == bereq.url &&\n beresp.ttl > 5s) {\n set beresp.ttl = 5s;\n set beresp.http.cache-control = \"max-age=5\";\n }\n\n \/* Request retrial *\/\n if ( beresp.status == 500\n || beresp.status == 503\n ) {\n #TODO# consider not restarting POST requests as seenV3 on https:\/\/www.varnish-cache.org\/trac\/wiki\/VCLExampleSaintMode\n return (retry);\n }\n\n \/* Enable grace mode. Related with vcl_hit *\/\n # See https:\/\/www.varnish-cache.org\/docs\/4.0\/users-guide\/vcl-grace.html\n set beresp.grace = 1h;\n\n \/* Strip cookies from the following static file types for all users. Related with our 12th stage on vcl_recv *\/\n if (bereq.url ~ \"(?i)\\.(png|gif|jpeg|jpg|ico|swf|css|js|html|htm|gz|tgz|bz2|tbz|mp3|ogg|zip|rar|otf|ttf|eot|woff|woff2|svg|pdf)(\\?(itok=)?[a-z0-9_=\\.\\-]+)?$\") {\n unset beresp.http.set-cookie;\n }\n\n \/* Gzip response *\/\n # Empty in simple configs\n # Use Varnish to Gzip respone, if suitable, before storing it on cache\n # See https:\/\/www.varnish-cache.org\/docs\/4.0\/users-guide\/compression.html\n # See https:\/\/www.varnish-cache.org\/docs\/4.0\/phk\/gzip.html\n if ( ! beresp.http.Content-Encoding\n && ( beresp.http.content-type ~ \"text\"\n || beresp.http.content-type ~ \"application\/x-javascript\"\n || beresp.http.content-type ~ \"application\/javascript\"\n || beresp.http.content-type ~ \"application\/rss+xml\"\n || beresp.http.content-type ~ \"application\/xml\"\n || beresp.http.content-type ~ \"Application\/JSON\")\n ) {\n set beresp.do_gzip = true;\n }\n\n \/* Debugging headers *\/\n # Please consider the risks of showing publicly this information, we can wrap this with an ACL\n # We can add the name of the backend that has processed the request:\n # set beresp.http.X-Backend = beresp.backend.name;\n # We can use a header to tell if the object was gziped by Varnish\n # if (beresp.do_gzip) {\n # set beresp.http.X-Varnish-Gzipped = \"yes\";\n # } else {\n # set beresp.http.X-Varnish-Gizipped = \"no\";\n # }\n # We can also add headers informing whether the object is cacheable or not and why.\n # https:\/\/www.varnish-cache.org\/trac\/wiki\/VCLExampleHitMissHeader#Varnish3.0\n if (beresp.ttl <= 0s) {\n \/* Varnish determined the object was not cacheable *\/\n set beresp.http.X-Cacheable = \"NO:Not Cacheable\";\n } elsif (bereq.http.Cookie ~ \"(SESS|SSESS|NO_CACHE|OATMEAL|CHOCOLATECHIP)\") {\n \/* We don't wish to cache content for logged in users or with certain cookies. Related with our 9th stage on vcl_recv *\/\n set beresp.http.X-Cacheable = \"NO:Cookies\";\n # return(hit_for_pass);\n } elsif (beresp.http.Cache-Control ~ \"private\") {\n \/* We are respecting the Cache-Control=private header from the backend *\/\n set beresp.http.X-Cacheable = \"NO:Cache-Control=private\";\n # return(hit_for_pass);\n } else {\n \/* Varnish determined the object was cacheable *\/\n set beresp.http.X-Cacheable = \"YES\";\n }\n\n \/* Further header manipulation *\/\n # Empty in simple configs.\n # We can also unset some headers to prevent information disclosure and save some cache space\n # unset beresp.http.Server;\n # unset beresp.http.X-Powered-By;\n # Retry count\n if ( bereq.retries > 0) {\n set beresp.http.X-Retries = bereq.retries;\n }\n\n \/* Continue with built-in logic *\/\n # We want built-in logic to be processed after ours so we don't call return.\n}\n# sub vcl_backend_response {\n# if (beresp.ttl <= 0s ||\n# beresp.http.Set-Cookie ||\n# beresp.http.Surrogate-control ~ \"no-store\" ||\n# (!beresp.http.Surrogate-Control &&\n# beresp.http.Cache-Control ~ \"no-cache|no-store|private\") ||\n# beresp.http.Vary == \"*\") {\n# \/*\n# * Mark as \"Hit-For-Pass\" for the next 2 minutes\n# *\/\n# set beresp.ttl = 120s;\n# set beresp.uncacheable = true;\n# }\n# return (deliver);\n# }\n\n# vcl_backend_error: This subroutine is called if we fail the backend fetch.\n# See https:\/\/www.varnish-cache.org\/docs\/4.0\/users-guide\/vcl-built-in-subs.html#vcl-backend-error\nsub vcl_backend_error {\n\n \/* Try to restart request in case of failure *\/\n #TODO# Confirm max_retries default value\n # SeeV3 https:\/\/www.varnish-cache.org\/trac\/wiki\/VCLExampleRestarts\n if (bereq.retries < 4) {\n return (retry);\n }\n\n \/* Debugging headers *\/\n # Please consider the risks of showing publicly this information, we can wrap this with an ACL\n # Retry count\n if ( bereq.retries > 0) {\n set beresp.http.X-Retries = bereq.retries;\n }\n\n set beresp.http.Content-Type = \"text\/html; charset=utf-8\";\n set beresp.http.Retry-After = \"5\";\n synthetic( {\"\n\n
\n\"} + beresp.reason + {\"<\/p>\n
XID: \"} + bereq.xid + {\"<\/p>\n
Varnish cache server<\/p>\n <\/body>\n<\/html>\n\"} );\n\n \/* Bypass built-in logic *\/\n # We make sure no built-in logic is processed after ours returning at this point.\n return (deliver);\n}\n\n#######################################################################\n# Housekeeping\n\n# vcl_init: Called when VCL is loaded, before any requests pass through it. Typically used to initialize VMODs.\n# See https:\/\/www.varnish-cache.org\/docs\/4.0\/users-guide\/vcl-built-in-subs.html#vcl-init\n# Here is where you should declare your directors now.\n# See https:\/\/www.varnish-cache.org\/docs\/4.0\/reference\/vmod_directors.generated.html\n# See https:\/\/www.varnish-cache.org\/docs\/4.0\/users-guide\/vcl-backends.html#directors\n# Empty in simple configs\n# sub vcl_init {\n# return (ok);\n# }\n\n# vcl_fini: Called when VCL is discarded only after all requests have exited the VCL. Typically used to clean up VMODs.\n# See https:\/\/www.varnish-cache.org\/docs\/4.0\/users-guide\/vcl-built-in-subs.html#vcl-fini\n# sub vcl_fini {\n# return (ok);\n# }\n\n","returncode":0,"stderr":"","license":"unknown","lang":"VCL"} {"commit":"b26fc96ad8727c86a1356bdf6c37e792e0c685dd","subject":"update varnish vcl to 4.0","message":"update varnish vcl to 4.0\n","repos":"KhanovaSkola\/khanovaskola-v3,KhanovaSkola\/khanovaskola-v3,KhanovaSkola\/khanovaskola-v3,KhanovaSkola\/khanovaskola-v3,KhanovaSkola\/khanovaskola-v3,KhanovaSkola\/khanovaskola-v3","old_file":"production\/varnish.vcl","new_file":"production\/varnish.vcl","new_contents":"vcl 4.0;\n\n# Disable esi xml check on varnish Startup\n# Example:\n# DAEMON_OPTS=\"-a :6081 \\\n# -T localhost:6082 \\\n# -p feature=+esi_disable_xml_check\n#\n\nbackend default {\n .host = \"127.0.0.1\";\n .port = \"8085\";\n}\n\nsub vcl_recv {\n\tif (req.method != \"GET\") {\n\t\treturn (pass);\n\t}\n\treturn (hash);\n}\n\nsub vcl_hash {\n\thash_data(req.url);\n\tif (req.url ~ \"\/esi\/headeruser($|\\?)\")\n\t{\n\t\thash_data(regsub(req.http.cookie, \".*PHPSESSID=([^;]+);.*\", \"\\1\"));\n\t}\n\treturn (lookup);\n}\n\nsub vcl_backend_response {\n\tset beresp.do_esi = true;\n\tset beresp.ttl = 15m;\n}\n","old_contents":"#\n# Requires Varnish 4\n#\n# Disable esi xml check on varnish Startup\n# Example:\n# DAEMON_OPTS=\"-a :6081 \\\n# -T localhost:6082 \\\n# -p feature=+esi_disable_xml_check\n#\n\nbackend default {\n .host = \"127.0.0.1\";\n .port = \"8085\";\n}\n\nsub vcl_hash {\n\thash_data(req.url);\n\tif (req.url ~ \"\/esi\/headeruser($|\\?)\")\n\t{\n\t\tset req.http.X-SID = regsub(req.http.cookie, \".*PHPSESSID=([^;]+);.*\", \"\\1\");\n\t\thash_data(req.http.X-SID);\n\t\tremove req.http.X-SID;\n\t}\n\treturn (hash);\n}\n\nsub vcl_recv {\n\tif (req.request != \"GET\") {\n\t\treturn (pass);\n\t}\n\treturn (lookup);\n}\n\nsub vcl_fetch {\n\tset beresp.do_esi = true;\n set beresp.ttl = 15m;\n}\n","returncode":0,"stderr":"","license":"mit","lang":"VCL"} {"commit":"22dc13452088e1c913ce11661eb24316ad2cce9b","subject":"Don't unset x-pass for bypass requests nor process any ESIs","message":"Don't unset x-pass for bypass requests nor process any ESIs\n","repos":"fastly\/fastly-magento2,fastly\/fastly-magento2,fastly\/fastly-magento2,fastly\/fastly-magento2","old_file":"etc\/vcl_snippets\/recv.vcl","new_file":"etc\/vcl_snippets\/recv.vcl","new_contents":" # When using Magento tester to test whether your site is configured properly\n # this uses a bypass secret. By default we will use service ID as the bypass secret\n # however user can override this by defining a bypass_secret key in the\n # magentomodule_config edge dictionary\n if ( req.http.bypass-secret ) {\n declare local var.bypass-secret STRING;\n set var.bypass-secret = table.lookup(magentomodule_config, \"bypass_secret\", \"NONE\");\n if ( var.bypass-secret == req.http.bypass-secret ) {\n set req.http.x-pass = \"1\";\n set var.fastly_req_do_shield = false;\n set req.hash_always_miss = true;\n set req.esi = false;\n } else if ( var.bypass-secret == \"NONE\" && req.http.bypass-secret == req.service_id ) {\n set req.http.x-pass = \"1\";\n set var.fastly_req_do_shield = false;\n set req.hash_always_miss = true;\n set req.esi = false;\n } else {\n error 403 \"Bypass Secret incorrect\";\n }\n\n if (req.url == \"\/fastly-io-tester\") {\n # IO won't work for PASS requests\n unset req.http.x-pass;\n # IO requires shielding\n set var.fastly_req_do_shield = true;\n set req.hash_always_miss = true;\n set req.http.X-Fastly-Imageopto-Api = \"fastly\";\n }\n }\n\n # VCL required to support maintenance mode. Don't maintenance mode admin pages and supporting assets\n if (table.lookup(magentomodule_config, \"allow_super_users_during_maint\", \"0\") == \"1\" &&\n !req.http.Fastly-Client-Ip ~ maint_allowlist &&\n !req.url ~ \"^\/(index\\.php\/)?####ADMIN_PATH####\/\" &&\n !req.url ~ \"^\/pub\/(static|error)\/\") {\n\n # If we end up here after a restart and there is a ResponseObject it means we got here after error\n # page VCL restart. We shouldn't touch it. Otherwise return a plain 503 error page\n if ( req.restarts > 0 && req.http.ResponseObject ) {\n set req.http.ResponseObject = \"970\";\n } else {\n error 503 \"Maintenance mode\";\n }\n }\n\n unset req.http.x-long-cache;\n\n # We want to force long cache times on any of the versioned assets\n if (req.url.path ~ \"^\/static\/version\\d*\/\") {\n set req.http.x-long-cache = \"1\";\n }\n\n # User's Cookie may contain some Magento Vary items we should vary on\n if (req.http.cookie:X-Magento-Vary) {\n set req.http.X-Magento-Vary = req.http.cookie:X-Magento-Vary;\n } else {\n unset req.http.X-Magento-Vary;\n }\n\n ############################################################################################################\n # Following code block controls purge by URL. By default we want to protect all URL purges. In general this\n # is addressed by adding Fastly-Purge-Requires-Auth request header in vcl_recv however this runs the risk of\n # exposing API tokens if user attempts to purge non-https URLs. For this reason inside the Magento module\n # we use X-Purge-Token. Unfortunately this breaks purge from the Fastly UI. Therefore in the next code block\n # we check for presence of X-Purge-Token. If it's not present we force the Fastly-Purge-Requires-Auth\n if (req.request == \"FASTLYPURGE\") {\n # extract token signature and expiration\n if (req.http.X-Purge-Token && req.http.X-Purge-Token ~ \"^([^_]+)_(.*)\" ) {\n\n declare local var.X-Exp STRING;\n declare local var.X-Sig STRING;\n \/* extract token expiration and signature *\/\n set var.X-Exp = re.group.1;\n set var.X-Sig = re.group.2;\n\n \/* validate signature *\/\n if (var.X-Sig == regsub(digest.hmac_sha1(req.service_id, req.url.path var.X-Exp), \"^0x\", \"\")) {\n \/* check that expiration time has not elapsed *\/\n if (time.is_after(now, std.integer2time(std.atoi(var.X-Exp)))) {\n error 410;\n }\n } else {\n error 403;\n }\n } else {\n set req.http.Fastly-Purge-Requires-Auth = \"1\";\n }\n }\n\n # set HTTPS header for offloaded TLS\n if (req.http.Fastly-SSL) {\n set req.http.Https = \"on\";\n }\n\n if (fastly.ff.visits_this_service > 0) {\n # disable ESI processing on Origin Shield\n set req.esi = false;\n # Needed for proper handling of stale while revalidated when shielding is involved\n set req.max_stale_while_revalidate = 0s;\n }\n\n # Make sure we lookup end user geo not shielding. More at https:\/\/docs.fastly.com\/vcl\/geolocation\/#using-geographic-variables-with-shielding\n set client.geo.ip_override = req.http.Fastly-Client-IP;\n\n if ((req.request == \"GET\" || req.request == \"HEAD\") && req.url.path ~ \"\/graphql\" && req.url.qs ~ \"query=\") {\n set req.http.graphql = \"1\";\n } else {\n unset req.http.graphql;\n }\n\n # geoip lookup\n if (req.url.path ~ \"fastlyCdn\/geoip\/getaction\/\") {\n # check if GeoIP has been already processed by client. this normally happens before essential cookies are set.\n if (req.http.cookie:X-Magento-Vary || req.http.cookie:form_key) {\n error 980 \"GeoIP already processed\";\n } else {\n # append parameter with country code only if it doesn't exist already\n if ( req.url.qs !~ \"country_code=\" ) {\n set req.url = querystring.set(req.url, \"country_code\", if ( req.http.geo_override, req.http.geo_override, client.geo.country_code));\n }\n }\n } else if ( req.url.path !~ \"\/graphql\" ) {\n # Per suggestions in https:\/\/github.com\/sdinteractive\/SomethingDigital_PageCacheParams\n # we'll strip out query parameters used in Google AdWords, Mailchimp tracking by default\n # and allow custom parameters to be set. List of parameters is configurable in admin\n set req.http.Magento-Original-URL = req.url;\n # Change the list of ignored parameters by configuring them in the Advanced section\n set req.url = querystring.regfilter(req.url, \"^(####QUERY_PARAMETERS####)$\");\n }\n\n # Don't allow clients to force a pass\n if (req.restarts == 0) {\n if ( !req.http.bypass-secret ) {\n unset req.http.x-pass;\n }\n unset req.http.Rate-Limit;\n unset req.http.magento-admin-path;\n }\n\n # Pass on checkout URLs. Because it's a snippet we want to execute this after backend selection so we handle it\n # in the request condition\n if (!req.http.x-long-cache && req.url ~ \"\/(checkout|customer\/section\/load)\") {\n set req.http.x-pass = \"1\";\n # Pass all admin actions\n # ####ADMIN_PATH#### is replaced with value of frontName from app\/etc\/env.php\n } else if ( req.url ~ \"^\/(index\\.php\/)?####ADMIN_PATH####\/\" ) {\n set req.http.x-pass = \"1\";\n set req.http.magento-admin-path = \"1\";\n } else {\n # Sort the query arguments to increase cache hit ratio with query arguments that\n # may be out od order. In case you want to restore the unsorted URL add a snippet\n # after this one that sets req.url to req.http.Magento-Original-URL\n if ( !req.http.x-pass ) {\n set req.url = boltsort.sort(req.url);\n }\n }\n\n # static files are always cacheable. remove SSL flag and cookie\n if (req.http.x-long-cache || req.url ~ \"^\/(pub\/)?(media|static)\/.*\") {\n unset req.http.Https;\n unset req.http.Cookie;\n }\n\n # GraphQL special headers handling because this area doesn't rely on X-Magento-Vary cookie\n if (req.http.graphql && !req.http.X-Magento-Cache-Id && req.http.Authorization ~ \"^Bearer\" ) {\n unset req.http.graphql;\n set req.http.x-pass = \"1\";\n }\n","old_contents":" # When using Magento tester to test whether your site is configured properly\n # this uses a bypass secret. By default we will use service ID as the bypass secret\n # however user can override this by defining a bypass_secret key in the\n # magentomodule_config edge dictionary\n if ( req.http.bypass-secret ) {\n declare local var.bypass-secret STRING;\n set var.bypass-secret = table.lookup(magentomodule_config, \"bypass_secret\", \"NONE\");\n if ( var.bypass-secret == req.http.bypass-secret ) {\n set req.http.x-pass = \"1\";\n set var.fastly_req_do_shield = false;\n set req.hash_always_miss = true;\n } else if ( var.bypass-secret == \"NONE\" && req.http.bypass-secret == req.service_id ) {\n set req.http.x-pass = \"1\";\n set var.fastly_req_do_shield = false;\n set req.hash_always_miss = true;\n } else {\n error 403 \"Bypass Secret incorrect\";\n }\n\n if (req.url == \"\/fastly-io-tester\") {\n # IO won't work for PASS requests\n unset req.http.x-pass;\n # IO requires shielding\n set var.fastly_req_do_shield = true;\n set req.hash_always_miss = true;\n set req.http.X-Fastly-Imageopto-Api = \"fastly\";\n }\n }\n\n # VCL required to support maintenance mode. Don't maintenance mode admin pages and supporting assets\n if (table.lookup(magentomodule_config, \"allow_super_users_during_maint\", \"0\") == \"1\" &&\n !req.http.Fastly-Client-Ip ~ maint_allowlist &&\n !req.url ~ \"^\/(index\\.php\/)?####ADMIN_PATH####\/\" &&\n !req.url ~ \"^\/pub\/(static|error)\/\") {\n\n # If we end up here after a restart and there is a ResponseObject it means we got here after error\n # page VCL restart. We shouldn't touch it. Otherwise return a plain 503 error page\n if ( req.restarts > 0 && req.http.ResponseObject ) {\n set req.http.ResponseObject = \"970\";\n } else {\n error 503 \"Maintenance mode\";\n }\n }\n\n unset req.http.x-long-cache;\n\n # We want to force long cache times on any of the versioned assets\n if (req.url.path ~ \"^\/static\/version\\d*\/\") {\n set req.http.x-long-cache = \"1\";\n }\n\n # User's Cookie may contain some Magento Vary items we should vary on\n if (req.http.cookie:X-Magento-Vary) {\n set req.http.X-Magento-Vary = req.http.cookie:X-Magento-Vary;\n } else {\n unset req.http.X-Magento-Vary;\n }\n\n ############################################################################################################\n # Following code block controls purge by URL. By default we want to protect all URL purges. In general this\n # is addressed by adding Fastly-Purge-Requires-Auth request header in vcl_recv however this runs the risk of\n # exposing API tokens if user attempts to purge non-https URLs. For this reason inside the Magento module\n # we use X-Purge-Token. Unfortunately this breaks purge from the Fastly UI. Therefore in the next code block\n # we check for presence of X-Purge-Token. If it's not present we force the Fastly-Purge-Requires-Auth\n if (req.request == \"FASTLYPURGE\") {\n # extract token signature and expiration\n if (req.http.X-Purge-Token && req.http.X-Purge-Token ~ \"^([^_]+)_(.*)\" ) {\n\n declare local var.X-Exp STRING;\n declare local var.X-Sig STRING;\n \/* extract token expiration and signature *\/\n set var.X-Exp = re.group.1;\n set var.X-Sig = re.group.2;\n\n \/* validate signature *\/\n if (var.X-Sig == regsub(digest.hmac_sha1(req.service_id, req.url.path var.X-Exp), \"^0x\", \"\")) {\n \/* check that expiration time has not elapsed *\/\n if (time.is_after(now, std.integer2time(std.atoi(var.X-Exp)))) {\n error 410;\n }\n } else {\n error 403;\n }\n } else {\n set req.http.Fastly-Purge-Requires-Auth = \"1\";\n }\n }\n\n # set HTTPS header for offloaded TLS\n if (req.http.Fastly-SSL) {\n set req.http.Https = \"on\";\n }\n\n if (fastly.ff.visits_this_service > 0) {\n # disable ESI processing on Origin Shield\n set req.esi = false;\n # Needed for proper handling of stale while revalidated when shielding is involved\n set req.max_stale_while_revalidate = 0s;\n }\n\n # Make sure we lookup end user geo not shielding. More at https:\/\/docs.fastly.com\/vcl\/geolocation\/#using-geographic-variables-with-shielding\n set client.geo.ip_override = req.http.Fastly-Client-IP;\n\n if ((req.request == \"GET\" || req.request == \"HEAD\") && req.url.path ~ \"\/graphql\" && req.url.qs ~ \"query=\") {\n set req.http.graphql = \"1\";\n } else {\n unset req.http.graphql;\n }\n\n # geoip lookup\n if (req.url.path ~ \"fastlyCdn\/geoip\/getaction\/\") {\n # check if GeoIP has been already processed by client. this normally happens before essential cookies are set.\n if (req.http.cookie:X-Magento-Vary || req.http.cookie:form_key) {\n error 980 \"GeoIP already processed\";\n } else {\n # append parameter with country code only if it doesn't exist already\n if ( req.url.qs !~ \"country_code=\" ) {\n set req.url = querystring.set(req.url, \"country_code\", if ( req.http.geo_override, req.http.geo_override, client.geo.country_code));\n }\n }\n } else if ( req.url.path !~ \"\/graphql\" ) {\n # Per suggestions in https:\/\/github.com\/sdinteractive\/SomethingDigital_PageCacheParams\n # we'll strip out query parameters used in Google AdWords, Mailchimp tracking by default\n # and allow custom parameters to be set. List of parameters is configurable in admin\n set req.http.Magento-Original-URL = req.url;\n # Change the list of ignored parameters by configuring them in the Advanced section\n set req.url = querystring.regfilter(req.url, \"^(####QUERY_PARAMETERS####)$\");\n }\n\n # Don't allow clients to force a pass\n if (req.restarts == 0) {\n unset req.http.x-pass;\n unset req.http.Rate-Limit;\n unset req.http.magento-admin-path;\n }\n\n # Pass on checkout URLs. Because it's a snippet we want to execute this after backend selection so we handle it\n # in the request condition\n if (!req.http.x-long-cache && req.url ~ \"\/(checkout|customer\/section\/load)\") {\n set req.http.x-pass = \"1\";\n # Pass all admin actions\n # ####ADMIN_PATH#### is replaced with value of frontName from app\/etc\/env.php\n } else if ( req.url ~ \"^\/(index\\.php\/)?####ADMIN_PATH####\/\" ) {\n set req.http.x-pass = \"1\";\n set req.http.magento-admin-path = \"1\";\n } else {\n # Sort the query arguments to increase cache hit ratio with query arguments that\n # may be out od order. In case you want to restore the unsorted URL add a snippet\n # after this one that sets req.url to req.http.Magento-Original-URL\n if ( !req.http.x-pass ) {\n set req.url = boltsort.sort(req.url);\n }\n }\n\n # static files are always cacheable. remove SSL flag and cookie\n if (req.http.x-long-cache || req.url ~ \"^\/(pub\/)?(media|static)\/.*\") {\n unset req.http.Https;\n unset req.http.Cookie;\n }\n\n # GraphQL special headers handling because this area doesn't rely on X-Magento-Vary cookie\n if (req.http.graphql && !req.http.X-Magento-Cache-Id && req.http.Authorization ~ \"^Bearer\" ) {\n unset req.http.graphql;\n set req.http.x-pass = \"1\";\n }\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"VCL"} {"commit":"737b17286ec3db3b9a5688b975fdf57351ec3a4e","subject":"Improved error response","message":"Improved error response\n","repos":"holderdeord\/hdo-puppet,holderdeord\/hdo-puppet,holderdeord\/hdo-puppet,holderdeord\/hdo-puppet,holderdeord\/hdo-puppet","old_file":"modules\/varnish\/templates\/fastly.vcl_error.vcl","new_file":"modules\/varnish\/templates\/fastly.vcl_error.vcl","new_contents":"sub vcl_error {\n if (obj.status == 801) {\n set obj.status = 301;\n set obj.response = \"Moved Permanently\";\n set obj.http.Location = \"https:\/\/\" req.http.host req.url;\n synthetic {\"\"};\n return (deliver);\n }\n\n if (req.http.Fastly-Restart-On-Error) {\n if (obj.status == 503 && req.restarts == 0) {\n restart;\n }\n }\n\n#--FASTLY ERROR START\n {\n if (obj.status == 550) {\n return(deliver);\n }\n }\n#--FASTLY ERROR END\n\n #\n # error response if all else fails\n #\n\n set obj.http.Content-Type = \"text\/html; charset=utf-8\";\n set obj.http.Retry-After = \"5\";\n\n synthetic {\"\n \n \n
\n \n