Skip to content

Instantly share code, notes, and snippets.

@rezan
rezan / vha_edgestash.vcl
Last active December 5, 2017 04:23
Edgestash VHA config
# Edgestash VHA config
vcl 6.0;
import edgestash;
# Look for Edgestash objects from VHA
sub vcl_backend_response
{
@rezan
rezan / prefetch_vary.vcl
Last active February 26, 2018 19:25
Prefetch Variations
vcl 4.0;
import http;
sub vcl_recv {
// Store Varnish's local address for later use
set req.http.X-prefetch = http.varnish_url(req.url);
}
sub vcl_backend_fetch {
@rezan
rezan / vary_errror.vtc
Created March 23, 2018 15:35
Vary with an error response
varnishtest "Test vary with error response"
server s1 {
# Normal responses
rxreq
txresp -hdr "Vary: test"
expect req.url == "/"
expect req.http.test == "1"
@rezan
rezan / vary_kvstore.vcl
Created March 23, 2018 15:48
Vary + kvstore
vcl 4.0;
import kvstore;
# https://docs.varnish-software.com/varnish-cache-plus/vmods/kvstore-4/
sub vcl_init
{
kvstore.init(0, 25000);
}
@rezan
rezan / magento.vcl
Created April 26, 2018 20:25
Magento 1.x VCL configuration
// Magento 1.x VCL configuration
vcl 4.0;
import cookieplus;
import edgestash;
import kvstore;
import xbody;
sub vcl_init
@rezan
rezan / aggregate.vcl
Created July 3, 2018 19:48
Aggregate response headers and body into a single response block
vcl 4.0;
# If you set req.http.X-aggregate = "true", Varnish will aggregate
# the headers and response body into a single response block
# Point this back to Varnish
#backend loop {
# .host = "127.0.0.1";
# .port = "80";
#}
@rezan
rezan / aggregate.vtc
Created July 3, 2018 19:48
Use aggregate.vcl to get the true response time in VCL for slow responses
varnishtest "Test using Varnish to aggregate headers and body"
server s1 {
rxreq
expect req.url == "/1"
txresp -nolen -hdr "Content-Length: 3"
delay 3
send "abc"
rxreq
@rezan
rezan / hit_miss.vcl
Last active July 20, 2018 13:57
hit_miss.vcl for Varnish 6.0
# hit_miss.vcl for Varnish 6.0
vcl 4.0;
# What are we, hit, miss, or pass?
sub vcl_recv {
set req.http.X-status = "NONE";
}
@rezan
rezan / csp_nonce.vtc
Created August 13, 2018 19:12
Generate CSP nonces for Javascript
varnishtest "Generate CSP nonces for Javascript"
server s1 {
rxreq
txresp -hdr "Content-Type: text/html" -body {
<html>
<script>
var a=1;
</script>
</html>
@rezan
rezan / json.vtc
Created September 25, 2018 15:23
Test JSON response body parsing
varnishtest "Test JSON response body parsing"
server s1 {
rxreq
txresp -body {
{
"key":"value",
"key2":23
}
}