A simple Google Chrome extension that shows if a page being served up via a Varnish web accelerator is fresh or not.
Currently this addon consists of a single toolbar button that changes state based on detected HTTP headers.
The button icon appears gray/disabled when no special HTTP headers are detected.
The button icon becomes Varnish-blue when the HTTP header Via
is detected containing the string "varnish":
The button becomes red-ish in color when the HTTP header X-Cache
is detected containing the string "MISS":
The button becomes green in color when the HTTP header X-Cache
is detected containing the string "HIT":
The label text is updated to reflect the number of cache hits if the HTTP header X-Cache-Hits
is present.
The current page cache can be cleared (i.e. purged / banned) by clicking on the extension icon.
If the page is cached:
Or if it is not:
To enable clearing of Varnish cache from the extension, we set an extra header, X-Purge-Key, with a secret key that is passed from the extension to Varnish. From Varnish, we check if the secret key exists and allow the purge. The secret key can be anything you want it to be.
This is is set in the following files:
- popup.js in the extension
- Varnish VCL configuration
7 xmlHttp.setRequestHeader("X-Purge-Key", "MYSUPERSECRETKEY");
Replace MYSUPERSECRETKEY with your secret key.
Example:
7 xmlHttp.setRequestHeader("X-Purge-Key", "$upercalifragilistic3xpialidocious");
If you're following the official Varnish Purge and banning configuration, add another expression to check if your secret key is passed along with the request. You can combine this with any other expressions.
if (req.request == "PURGE") {
if (!client.ip ~ purgers && req.http.X-Purge-Key != "MYSUPERSECRETKEY") {
error 405 "Method not allowed";
}
return (lookup);
}
Replace MYSUPERSECRETKEY with your secret key.
Example:
if (req.request == "PURGE") {
if (!client.ip ~ purgers && req.http.X-Purge-Key != "$upercalifragilistic3xpialidocious") {
error 405 "Method not allowed";
}
return (lookup);
}
If you see this:
Make sure your secret key is the same in both popup.js and your Varnish VCL.
- Add configuration dialog to set secret key from extension