Skip to content

Instantly share code, notes, and snippets.

@rezan
rezan / xbody_etag.vtc
Created Mar 20, 2020
Generate an ETag with xbody
View xbody_etag.vtc
varnishtest "Use xbody to generate an Etag"
server s1 {
rxreq
txresp -body "This is a test"
} -start
varnish v1 -vcl+backend {
import crypto;
import xbody;
@rezan
rezan / jwt_jwk.vcl
Created Mar 2, 2020
Varnish VCL example for JWT and JWK
View jwt_jwk.vcl
#
# JWT - Remote JWK API
#
vcl 4.1;
import edgestash;
import goto;
import http;
import json;
@rezan
rezan / self.vtc
Created Feb 11, 2020
VTC with v1 routing to itself
View self.vtc
varnishtest "VTC with v1 routing to itself"
# Start v1 with no VCL so we can get a addr and port
server s1 {} -start
varnish v1 -vcl+backend {} -start
varnish v1 -vcl+backend {
backend self
{
.host = "${v1_addr}";
@rezan
rezan / post_timeout.vtc
Created Jan 7, 2020
Request POST body timeout
View post_timeout.vtc
varnishtest "Test HTTP Post timeout"
server s1 -repeat 3 {
rxreq
txresp
expect req.body == "postdata is here"
} -start
varnish v1 -arg "-p timeout_idle=3.0" -vcl+backend {
sub vcl_recv {
@rezan
rezan / jsonp.vcl
Last active Dec 2, 2019
Varnish VCL JSONP support
View jsonp.vcl
import urlplus;
import xbody;
sub vcl_backend_response {
# Insert the JSONP callback
if (urlplus.query_get("callback") && beresp.http.Content-Type ~ "json") {
xbody.regsub("^", urlplus.query_get("callback") + "(");
xbody.regsub("$", ");");
set beresp.http.Content-Type = regsub(beresp.http.Content-Type, "json", "javascript");
}
@rezan
rezan / jsonp.vtc
Last active Dec 2, 2019
Varnish VCL JSON support (test)
View jsonp.vtc
varnishtest "JSONP support"
server s1 -repeat 2 {
rxreq
txresp -hdr "Content-Type: application/json" -body {"json"}
} -start
varnish v1 -vcl+backend {
import urlplus;
import xbody;
@rezan
rezan / validate_json.vtc
Last active Nov 7, 2019
Varnish: validate JSON, if invalid, refetch
View validate_json.vtc
varnishtest "Validate JSON, if invalid, refetch"
server s1 {
rxreq
txresp -hdr "Content-Type: application/json" -body {
{
"some": "field",
"error...bad json
}
}
@rezan
rezan / shard_test.vcl
Created Nov 5, 2019
Test how accurately a shard reconfiguration will remap
View shard_test.vcl
# Shard reconfiguration accuracy
# Create two different shard configurations, s1 and s2
# See what percentage of URLs map the same (200) vs different (500)
vcl 4.0;
import crypto;
import directors;
backend b01 { .host = "0"; }
@rezan
rezan / multi_purge.vcl
Last active Sep 11, 2019
Purge multiple urls from a request body
View multi_purge.vcl
# Purge multiple urls from a request body
import edgestash;
import synthbackend;
import xbody;
sub vcl_recv {
unset req.http.purgelist;
if (req_top.method == "PURGELIST") {
if (req.esi_level == 0) {
@rezan
rezan / multi_purge.vtc
Created Sep 11, 2019
Purge multiple URLs from a request body
View multi_purge.vtc
varnishtest "Multipurging"
server s1 {
} -start
varnish v1 -vcl+backend {
import edgestash;
import synthbackend;
import xbody;