updated readme
updated readme

file:a/readme.txt -> file:b/readme.txt
--- a/readme.txt
+++ b/readme.txt
@@ -1,1 +1,73 @@
+=== Varnish Caching ===
+Donate: PAYPAL razvan_stanga@yahoo.com
+Contributors: razvanstanga
+Tags: varnish, purge, cache
+Requires at least: 4.0
+Tested up to: 4.3
+Stable tag: 3.7.3
+License: GPLv2 or later
 
+Varnish Cache Wordpress implementation
+
+== Description ==
+Varnish Cache Wordpress implementation
+
+You can control from the Varnish Cache admin panel the following :
+- Enable/Disable caching
+- Homepage cache TTL
+- Cache TTL (for every other page)
+- IPs/Hosts to clear cache to support every type of Varnish Cache implementation
+- Override default TTL in posts/pages
+- Purge key based PURGE
+- Debugging option
+
+Purges Varnish Cache when your site is modified.
+Varnish Caching sends a PURGE request to Varnish Cache when a page or post is modified. This occurs when editing, publishing, commenting or deleting an item, and when changing themes.
+
+<a href="https://www.varnish-cache.org/">Varnish</a> is a web application accelerator also known as a caching HTTP reverse proxy. You install it in front of any server that speaks HTTP and configure it to cache the contents. This plugin <em>does not</em> install Varnish for you, nor does it configure Varnish for WordPress. It's expected you already did that on your own using the provided config files.
+
+Not all pages are purged every time, depending on your Varnish configuration. When a post, page, or custom post type is edited, or a new comment is added, <em>only</em> the following pages will purge:
+
+* The front page
+* The post/page edited
+* Any categories or tags associated with the page
+
+Inspired from the following :
+- https://wordpress.org/plugins/varnish-http-purge/
+- https://github.com/dreamhost/varnish-vcl-collection/
+
+Implemented on :
+- www.bvoltaire.fr
+
+== Installation ==
+Use the provided config files for Varnish Cache. Just edit the backend IP and port.
+
+== Frequently Asked Questions ==
+
+= What version of Varnish is supported? =
+
+This was built and tested on Varnish 3.x. It is only supported on v3 at this time.
+
+= Why doesn't every page flush when I make a new post? =
+
+The only pages that should purge are the post's page, the front page, categories, and tags.
+
+= How do I manually purge the whole cache? =
+
+Click the 'Purge ALL Varnish Cache' button on the "Right Now" Dashboard
+
+== Changelog ==
+
+= 1.1 =
+* Play nice with W3 Total Cache
+
+= 1.0 =
+* Initial commit
+
+== Upgrade Notice ==
+
+* none
+
+== Screenshots ==
+
+* soon

--- a/varnish-caching.php
+++ b/varnish-caching.php
@@ -59,13 +59,13 @@
     {
         load_plugin_textdomain($this->plugin);
 
-        add_action('wp', array($this, 'buffer_start'));
-        add_action('shutdown', array($this, 'buffer_end'));
+        add_action('wp', array($this, 'buffer_start'), 1000000);
+        add_action('shutdown', array($this, 'buffer_end'), 1000000);
 
         $this->debug = get_option($this->prefix . 'debug');
 
         // send headers to varnish
-        add_action('send_headers', array($this, 'send_headers'));
+        add_action('send_headers', array($this, 'send_headers'), 1000000);
 
         // register events to purge post
         foreach ($this->getRegisterEvents() as $event) {
@@ -91,26 +91,39 @@
             add_action('admin_menu', array($this, 'createCustomFields'));
             add_action('save_post', array($this, 'saveCustomFields' ), 1, 2);
         }
-        add_filter('the_post', array($this, 'override_ttl'));
+        add_action('wp_enqueue_scripts', array($this, 'override_ttl'), 1000);
+        add_action('wp_enqueue_scripts', array($this, 'override_homepage_ttl'), 1000);
     }
 
     public function override_ttl($post)
     {
-        if (is_page() || is_singular() ) {
-            $ttl = get_post_meta($post->ID, $this->prefix . 'ttl', true);
-            Header('Cache-Control: max-age=' . $ttl, true);
-        }
-    }
-
-    public function callback($buffer) {
+        $postId = isset($GLOBALS['wp_the_query']->post->ID) ? $GLOBALS['wp_the_query']->post->ID : 0;
+        if ($postId && (is_page() || is_single())) {
+            $ttl = get_post_meta($postId, $this->prefix . 'ttl', true);
+            Header('X-VC-TTL: ' . $ttl, true);
+        }
+    }
+
+    public function override_homepage_ttl()
+    {
+        if (is_home() || is_front_page()) {
+            $this->homepage_ttl = get_option($this->prefix . 'homepage_ttl');
+            Header('X-VC-TTL: ' . $this->homepage_ttl, true);
+        }
+    }
+
+    public function buffer_callback($buffer)
+    {
         return $buffer;
     }
 
-    public function buffer_start() {
-        ob_start(array($this, "callback"));
-    }
-
-    public function buffer_end() {
+    public function buffer_start()
+    {
+        ob_start(array($this, "buffer_callback"));
+    }
+
+    public function buffer_end()
+    {
         ob_end_flush();
     }
 
@@ -158,7 +171,7 @@
         }
     }
 
-    function displayCustomFields()
+    public function displayCustomFields()
     {
         global $post;
         ?>
@@ -423,12 +436,14 @@
     {
         $enable = get_option($this->prefix . 'enable');
         if ($enable) {
-            Header('X-VC-Enabled: true');
+            Header('X-VC-Enabled: true', true);
             $ttl = get_option($this->prefix . 'ttl');
-            Header('Cache-Control: max-age=' . $ttl);
+            Header('X-VC-TTL: ' . $ttl, true);
             if ($debug = get_option($this->prefix . 'debug')) {
-                Header('X-VC-Debug: true');
-            }
+                Header('X-VC-Debug: true', true);
+            }
+        } else {
+            Header('X-VC-Enabled: false', true);
         }
     }
 
@@ -464,6 +479,7 @@
         add_settings_section('section', 'Settings', null, $this->plugin . '-options');
 
         add_settings_field($this->prefix . "enable", __("Enable" , $this->plugin), array($this, $this->prefix . "enable"), $this->plugin . '-options', "section");
+        add_settings_field($this->prefix . "homepage_ttl", __("Homepage cache TTL", $this->plugin), array($this, $this->prefix . "homepage_ttl"), $this->plugin . '-options', "section");
         add_settings_field($this->prefix . "ttl", __("Cache TTL", $this->plugin), array($this, $this->prefix . "ttl"), $this->plugin . '-options', "section");
         add_settings_field($this->prefix . "ips", __("IPs", $this->plugin), array($this, $this->prefix . "ips"), $this->plugin . '-options', "section");
         add_settings_field($this->prefix . "dynamic_host", __("Dynamic host", $this->plugin), array($this, $this->prefix . "dynamic_host"), $this->plugin . '-options', "section");
@@ -476,6 +492,7 @@
 
         register_setting("section", $this->prefix . "enable");
         register_setting("section", $this->prefix . "ttl");
+        register_setting("section", $this->prefix . "homepage_ttl");
         register_setting("section", $this->prefix . "ips");
         register_setting("section", $this->prefix . "dynamic_host");
         register_setting("section", $this->prefix . "hosts");
@@ -492,6 +509,14 @@
         <?php
     }
 
+    public function varnish_caching_homepage_ttl()
+    {
+        ?>
+            <input type="text" name="varnish_caching_homepage_ttl" id="varnish_caching_homepage_ttl" value="<?php echo get_option($this->prefix . 'homepage_ttl'); ?>" />
+            <p class="description"><?=__('Time to live in seconds in Varnish cache for homepage', $this->plugin)?></p>
+        <?php
+    }
+
     public function varnish_caching_ttl()
     {
         ?>
@@ -550,6 +575,9 @@
     {
         ?>
             <input type="checkbox" name="varnish_caching_debug" value="1" <?php checked(1, get_option($this->prefix . 'debug'), true); ?> />
+            <p class="description">
+                <?=__('Send all debugging headers to the client. Also shows complete response from Varnish on purge all.', $this->plugin)?>
+            </p>
         <?php
     }
 }

--- a/varnish-conf/README.rst
+++ b/varnish-conf/README.rst
@@ -101,6 +101,9 @@
 and attempt to automatically pick the best method based on the URL if you
 don't use an X-Purge-Method header.  See the comments in `lib/purge.vcl` for
 details.
+You can also use the X-VC-Purge-Key method. Generate a MD5/SHA-256 hash and fill it on line
+if (req.http.X-VC-Purge-Key == "hash-to-be-filled-in") {
+in lib/purge.vcl. Then use the same hash in Varnish Caching WP admin.
 
 
 Static File Caching

--- a/varnish-conf/default.vcl
+++ b/varnish-conf/default.vcl
@@ -49,14 +49,18 @@
     if (req.request != "GET" && req.request != "HEAD") {
         return(pass);
     }
+
     # don't cache logged-in users or authors
     if (req.http.Cookie ~ "wp-postpass_|wordpress_logged_in_|comment_author|PHPSESSID") {
+        set req.http.X-VC-GotSession = "true";
         return(pass);
     }
+
     # don't cache ajax requests
     if (req.http.X-Requested-With == "XMLHttpRequest") {
         return(pass);
     }
+
     # don't cache these special pages
     if (req.url ~ "nocache|wp-admin|wp-(comments-post|login|activate|mail)\.php|bb-admin|server-status|control\.php|bb-login\.php|bb-reset-password\.php|register\.php") {
         return(pass);
@@ -96,19 +100,24 @@
         set beresp.grace = 2m;
     }
 
+    # overwrite ttl with X-VC-TTL
+    if (beresp.http.X-VC-TTL) {
+        set beresp.ttl = std.duration(beresp.http.X-VC-TTL + "s", 0s);
+    }
+
     # catch obvious reasons we can't cache
     if (beresp.http.Set-Cookie) {
         set beresp.ttl = 0s;
     }
 
-    # Varnish determined the object was not cacheable
-    if (beresp.ttl <= 0s) {
-        set beresp.http.X-VC-Cacheable = "NO:Not Cacheable";
+    # You don't wish to cache content for logged in users
+    if (req.http.Cookie ~ "wp-postpass_|wordpress_logged_in_|comment_author|PHPSESSID") {
+        set beresp.http.X-VC-Cacheable = "NO:Got Session";
         return(hit_for_pass);
 
-    # You don't wish to cache content for logged in users
-    } else if (req.http.Cookie ~ "wp-postpass_|wordpress_logged_in_|comment_author|PHPSESSID") {
-        set beresp.http.X-VC-Cacheable = "NO:Got Session";
+    # Varnish determined the object was not cacheable
+    } else if (beresp.ttl <= 0s) {
+        set beresp.http.X-VC-Cacheable = "NO:Not Cacheable";
         return(hit_for_pass);
 
     # You are respecting the Cache-Control=private header from the backend

--- a/varnish-conf/lib/bigfiles.vcl
+++ b/varnish-conf/lib/bigfiles.vcl
@@ -1,9 +1,9 @@
 # bigfiles.vcl -- Bypass Cache for Large Files
 
 sub vcl_fetch {
-	# Bypass cache for files > 10 MB
-	if (std.integer(beresp.http.Content-Length, 0) > 10485760) {
-		return (hit_for_pass);
-	}
+    # Bypass cache for files > 10 MB
+    if (std.integer(beresp.http.Content-Length, 0) > 10485760) {
+        return (hit_for_pass);
+    }
 }
 

--- a/varnish-conf/lib/bigfiles_pipe.vcl
+++ b/varnish-conf/lib/bigfiles_pipe.vcl
@@ -1,37 +1,23 @@
 # bigfiles_pipe.vcl -- Pipe for Large Files
-#
-# Copyright (C) 2013 DreamHost (New Dream Network, LLC)
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 # You must have "import std;" in your main vcl:
 # import std;
 
 # NOTE: Using restart and pipe is a workaround for a bug in varnish prior to
 # 3.0.3.  In 3.0.3+, hit_for_pass in vcl_fetch is all that is necessary.
+
 sub vcl_recv {
-	if (req.http.X-Pipe-Big-File && req.restarts > 0) {
-		unset req.http.X-Pipe-Big-File;
-		return (pipe);
-	}
+    if (req.http.X-Pipe-Big-File && req.restarts > 0) {
+        unset req.http.X-Pipe-Big-File;
+        return (pipe);
+    }
 }
 
 sub vcl_fetch {
-	# Bypass cache for files > 10 MB
-	if (std.integer(beresp.http.Content-Length, 0) > 10485760) {
-		set req.http.X-Pipe-Big-File = "Yes";
-		return (restart);
-	}
+    # Bypass cache for files > 10 MB
+    if (std.integer(beresp.http.Content-Length, 0) > 10485760) {
+        set req.http.X-Pipe-Big-File = "Yes";
+        return (restart);
+    }
 }
 

--- a/varnish-conf/lib/cloudflare.vcl
+++ b/varnish-conf/lib/cloudflare.vcl
@@ -1,56 +1,41 @@
 # cloudflare.vcl -- CloudFlare HTTP Headers
-#
-# Copyright (C) 2013 DreamHost (New Dream Network, LLC)
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 # This should generally be loaded first to make sure that the headers
 # get set appropriately for all requests.
 
 acl official_cloudflare {
-	# https://www.cloudflare.com/ips-v4
-	"204.93.240.0"/24;
-	"204.93.177.0"/24;
-	"199.27.128.0"/21;
-	"173.245.48.0"/20;
-	"103.21.244.0"/22;
-	"103.22.200.0"/22;
-	"103.31.4.0"/22;
-	"141.101.64.0"/18;
-	"108.162.192.0"/18;
-	"190.93.240.0"/20;
-	"188.114.96.0"/20;
-	"197.234.240.0"/22;
-	"198.41.128.0"/17;
-	"162.158.0.0"/15;
-	# https://www.cloudflare.com/ips-v6
-	"2400:cb00::"/32;
-	"2606:4700::"/32;
-	"2803:f800::"/32;
-	"2405:b500::"/32;
-	"2405:8100::"/32;
+    # https://www.cloudflare.com/ips-v4
+    "204.93.240.0"/24;
+    "204.93.177.0"/24;
+    "199.27.128.0"/21;
+    "173.245.48.0"/20;
+    "103.21.244.0"/22;
+    "103.22.200.0"/22;
+    "103.31.4.0"/22;
+    "141.101.64.0"/18;
+    "108.162.192.0"/18;
+    "190.93.240.0"/20;
+    "188.114.96.0"/20;
+    "197.234.240.0"/22;
+    "198.41.128.0"/17;
+    "162.158.0.0"/15;
+    # https://www.cloudflare.com/ips-v6
+    "2400:cb00::"/32;
+    "2606:4700::"/32;
+    "2803:f800::"/32;
+    "2405:b500::"/32;
+    "2405:8100::"/32;
 }
 
 sub vcl_recv {
-	# Set the CF-Connecting-IP header
-	# If the client.ip is trusted, we leave the header alone if present.
-	if (req.http.CF-Connecting-IP) {
-		if (client.ip !~ official_cloudflare && client.ip !~ cloudflare) {
-			set req.http.CF-Connecting-IP = client.ip;
-		}
-	} else {
-		set req.http.CF-Connecting-IP = client.ip;
-	}
+    # Set the CF-Connecting-IP header
+    # If the client.ip is trusted, we leave the header alone if present.
+    if (req.http.CF-Connecting-IP) {
+        if (client.ip !~ official_cloudflare && client.ip !~ cloudflare) {
+            set req.http.CF-Connecting-IP = client.ip;
+        }
+    } else {
+        set req.http.CF-Connecting-IP = client.ip;
+    }
 }
 

--- a/varnish-conf/lib/mobile_cache.vcl
+++ b/varnish-conf/lib/mobile_cache.vcl
@@ -1,19 +1,4 @@
 # mobile_cache.vcl -- Separate cache for mobile clients
-#
-# Copyright (C) 2013 DreamHost (New Dream Network, LLC)
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 # If the User-Agent looks like a mobile device, then we add the string
 # "mobile" to the hash_data.  This results in mobile devices having
@@ -25,10 +10,11 @@
 # Also if the backend disagrees with this logic as far as what is a
 # "mobile" User-Agent, then we may save the wrong version of pages in
 # the cache.
+
 sub vcl_hash {
-	# General User-Agent list (anything that remotely looks like a mobile device)
-	if (req.http.User-Agent ~ "(?i)ipod|android|blackberry|phone|mobile|kindle|silk|fennec|tablet|webos|palm|windows ce|nokia|philips|samsung|sanyo|sony|panasonic|ericsson|alcatel|series60|series40|opera mini|opera mobi|au-mic|audiovox|avantgo|blazer|danger|docomo|epoc|ericy|i-mode|ipaq|midp-|mot-|netfront|nitro|pocket|portalmmm|rover|sie-|symbian|cldc-|j2me|up\.browser|up\.link|vodafone|wap1\.|wap2\.") {
-		hash_data("mobile");
-	}
+    # General User-Agent list (anything that remotely looks like a mobile device)
+    if (req.http.User-Agent ~ "(?i)ipod|android|blackberry|phone|mobile|kindle|silk|fennec|tablet|webos|palm|windows ce|nokia|philips|samsung|sanyo|sony|panasonic|ericsson|alcatel|series60|series40|opera mini|opera mobi|au-mic|audiovox|avantgo|blazer|danger|docomo|epoc|ericy|i-mode|ipaq|midp-|mot-|netfront|nitro|pocket|portalmmm|rover|sie-|symbian|cldc-|j2me|up\.browser|up\.link|vodafone|wap1\.|wap2\.") {
+        hash_data("mobile");
+    }
 }
 

--- a/varnish-conf/lib/mobile_pass.vcl
+++ b/varnish-conf/lib/mobile_pass.vcl
@@ -1,36 +1,22 @@
 # mobile_pass.vcl -- Mobile pass-through support for Varnish
-#
-# Copyright (C) 2013 DreamHost (New Dream Network, LLC)
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 # This simply bypasses the cache for anything that looks like a mobile
 # (or tablet) device.
 # Also passes through some requests that are specifically for the WordPress
 # Jetpack mobile plugin.
+
 sub vcl_recv {
-	# Rules specifically for the Jetpack Mobile module
-	if (req.url ~ "\?(.*&)?(ak_action|app-download)=") {
-		return(pass);
-	}
-	if (req.http.Cookie ~ "(^|;\s*)akm_mobile=") {
-		return(pass);
-	}
+    # Rules specifically for the Jetpack Mobile module
+    if (req.url ~ "\?(.*&)?(ak_action|app-download)=") {
+        return(pass);
+    }
+    if (req.http.Cookie ~ "(^|;\s*)akm_mobile=") {
+        return(pass);
+    }
 
-	# General User-Agent blacklist (anything that remotely looks like a mobile device)
-	if (req.http.User-Agent ~ "(?i)ipod|android|blackberry|phone|mobile|kindle|silk|fennec|tablet|webos|palm|windows ce|nokia|philips|samsung|sanyo|sony|panasonic|ericsson|alcatel|series60|series40|opera mini|opera mobi|au-mic|audiovox|avantgo|blazer|danger|docomo|epoc|ericy|i-mode|ipaq|midp-|mot-|netfront|nitro|pocket|portalmmm|rover|sie-|symbian|cldc-|j2me|up\.browser|up\.link|vodafone|wap1\.|wap2\.") {
-		return(pass);
-	}
+    # General User-Agent blacklist (anything that remotely looks like a mobile device)
+    if (req.http.User-Agent ~ "(?i)ipod|android|blackberry|phone|mobile|kindle|silk|fennec|tablet|webos|palm|windows ce|nokia|philips|samsung|sanyo|sony|panasonic|ericsson|alcatel|series60|series40|opera mini|opera mobi|au-mic|audiovox|avantgo|blazer|danger|docomo|epoc|ericy|i-mode|ipaq|midp-|mot-|netfront|nitro|pocket|portalmmm|rover|sie-|symbian|cldc-|j2me|up\.browser|up\.link|vodafone|wap1\.|wap2\.") {
+        return(pass);
+    }
 }
 

--- a/varnish-conf/lib/purge.vcl
+++ b/varnish-conf/lib/purge.vcl
@@ -1,3 +1,4 @@
+# purge.vcl -- Cache Purge Library for Varnish
 
 # Regex purging
 # Treat the request URL as a regular expression.
@@ -85,10 +86,13 @@
     if (resp.http.X-VC-Debug ~ "true") {
         set resp.http.X-VC-Hash = req.url+"#"+req.http.host;
     } else {
+        unset resp.http.X-VC-Enabled;
+        unset resp.http.X-VC-Cache;
         unset resp.http.X-VC-Debug;
-        unset resp.http.X-VC-Enabled;
         unset resp.http.X-VC-Cacheable;
         unset resp.http.X-VC-Purge-Key-Auth;
+        unset resp.http.X-VC-TTL;
+        unset resp.http.X-VC-GotSession;
     }
 }
 

--- a/varnish-conf/lib/static.vcl
+++ b/varnish-conf/lib/static.vcl
@@ -1,26 +1,27 @@
 # static.vcl -- Static File Caching for Varnish
 
 sub vcl_recv {
-	if (req.request ~ "^(GET|HEAD)$" && req.url ~ "\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html|htm)(\?.*)?$") {
-		# disable this if you want
-		if (req.url ~ "nocache") {
-			return(pass);
-		}
-		set req.url = regsub(req.url, "\?.*$", "");
-		unset req.http.Cookie;
-		set req.grace = 2m;
-		return(lookup);
-	}
+    if (req.request ~ "^(GET|HEAD)$" && req.url ~ "\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html|htm)(\?.*)?$") {
+        # disable this if you want
+        if (req.url ~ "nocache") {
+            return(pass);
+        }
+        set req.url = regsub(req.url, "\?.*$", "");
+        # unset cookie only if no http auth
+        if (!req.http.Authorization) {
+            unset req.http.Cookie;
+        }
+        set req.grace = 2m;
+        return(lookup);
+    }
 }
 
 sub vcl_fetch {
-	if (req.request ~ "^(GET|HEAD)$" && req.url ~ "\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html|htm)$") {
-		# unset cookie only if no http auth is requested
-		if (!req.http.Authorization) {
-			unset beresp.http.set-cookie;
-		}
-		set beresp.ttl = 24h;
-		set beresp.grace = 2m;
-	}
+    if (req.request ~ "^(GET|HEAD)$" && req.url ~ "\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html|htm)$") {
+        # overwrite ttl with X-VC-TTL
+        set beresp.http.X-VC-TTL = "24";
+        set beresp.ttl = std.duration(beresp.http.X-VC-TTL + "h", 0s);
+        set beresp.grace = 2m;
+    }
 }
 

--- a/varnish-conf/lib/xforward.vcl
+++ b/varnish-conf/lib/xforward.vcl
@@ -1,66 +1,17 @@
 # xforward.vcl -- X-Forwarded-For HTTP Headers
-#
-# Copyright (C) 2013 DreamHost (New Dream Network, LLC)
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-#
-# This file contains some of the default VCL code.  Original copyright
-# and license:
-
-/*
- * Copyright (c) 2006 Verdens Gang AS
- * Copyright (c) 2006-2011 Varnish Software AS
- * All rights reserved.
- *
- * Author: Poul-Henning Kamp <phk@phk.freebsd.dk>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
- * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
 
 # This should generally be loaded first to make sure that the headers
 # get set appropriately for all requests.  Note that when using this
 # you MUST NOT fall through to the VCL default handler for vcl_recv
 # since that will run the code again, resulting in the client.ip
 # being added twice.
+
 sub vcl_recv {
-#	if (req.restarts == 0) {
-		if (req.http.X-Forwarded-For) {
-			set req.http.X-Forwarded-For =
-				req.http.X-Forwarded-For + ", " + client.ip;
-		} else {
-			set req.http.X-Forwarded-For = client.ip;
-		}
-#	}
+    if (req.http.X-Forwarded-For) {
+        set req.http.X-Forwarded-For =
+            req.http.X-Forwarded-For + ", " + client.ip;
+    } else {
+        set req.http.X-Forwarded-For = client.ip;
+    }
 }
 

comments