Skip to content

Instantly share code, notes, and snippets.

@rezan
rezan / S00002.vtc
Created July 6, 2020 18:22
varnishscoreboard parallel ESI
varnishtest "varnishscoreboard parallel ESI"
barrier b1 cond 3
barrier b2 cond 3
server s1 {
rxreq
txresp -body {
<esi:include src="/c1"/>
<esi:include src="/c2"/>
@rezan
rezan / client_error.vtc
Created June 18, 2020 19:35
Varnish client download error
varnishtest "varnishncsa logging a client error"
server s1 {
rxreq
txresp -bodylen 10000000
} -start
varnish v1 -vcl+backend {
} -start
@rezan
rezan / goto_fallback.vtc
Created May 7, 2020 13:59
Varnish - goto and fallback
varnishtest "Goto and fallbacks"
server s1 {
rxreq
txresp
expect req.url == "/probe"
accept
rxreq
txresp
@rezan
rezan / s3_v4_signing.vcl
Last active April 22, 2020 07:03
S3 v4 request signing in VCL
#
# S3 v4 request signing (v1.6)
#
import crypto;
import goto;
import kvstore;
import std;
import urlplus;
import utils;
@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");
}