Skip to content

Instantly share code, notes, and snippets.

@rezan
rezan / aws_secrets_manager.vcl
Created April 15, 2020 15:47
AWS Secrets Manager Varnish VCL Implementation
#
# AWS Secrets Manager v1.0
#
import crypto;
import http;
import json;
import kvstore;
import utils;
@rezan
rezan / xbody_etag.vtc
Created March 20, 2020 20:41
Generate an ETag with xbody
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 March 2, 2020 17:16
Varnish VCL example for JWT and JWK
#
# JWT - Remote JWK API
#
vcl 4.1;
import edgestash;
import goto;
import http;
import json;
@rezan
rezan / self.vtc
Created February 11, 2020 15:23
VTC with v1 routing to itself
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 January 7, 2020 19:50
Request POST body timeout
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 December 2, 2019 23:00
Varnish VCL JSONP support
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 December 2, 2019 23:00
Varnish VCL JSON support (test)
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 November 7, 2019 16:56
Varnish: validate JSON, if invalid, refetch
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 November 5, 2019 00:08
Test how accurately a shard reconfiguration will remap
# 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 September 11, 2019 18:21
Purge multiple urls from a request body
# 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) {