Skip to content

Instantly share code, notes, and snippets.

@rezan
rezan / multi_tier_response.vcl
Last active July 19, 2017 16:11
A simplified version of a multi tier response pipeline
vcl 6.0;
# Logic for passing response objects thru a distributed VCL architecture
import std;
sub vcl_backend_response
{
if (beresp.http.X-DVCL-ttl) {
set beresp.ttl = std.duration(beresp.http.X-DVCL-ttl, 0s);
@rezan
rezan / cache_control_es.vtc
Created August 1, 2017 14:00
Updating the Cache-Control to reflect the smallest TTL included (Edgestash)
varnishtest "Updating the Cache-Control to reflect the smallest TTL included (Edgestash)"
server s1 {
rxreq
txresp -hdr "Cache-Control: max-age=3600" -body {
This is a response with 2 partials
{{ > /include/p1 }}
{{ > /include/p2 }}
}
expect req.url == "/page"
@rezan
rezan / vmod_json.vcc
Created August 2, 2017 20:44
JSON prototype
$Module json 3 JSON parsing
DESCRIPTION
===========
JSON parsing
$Function VOID parse(PRIV_TASK, STRING json)
Parse the JSON string.
@rezan
rezan / ims_es.vtc
Last active August 9, 2017 17:46
Updating the Last-Modified to capture Edgestash partials
varnishtest "Updating the Last-Modified to capture Edgestash partials"
server s1 {
# Content
rxreq
txresp -hdr "Last-Modified: Wed, 09 Aug 2017 12:00:00 GMT" -body {
This is a response with 2 partials
{{ > /include/p1 }}
{{ > /include/p2 }}
@rezan
rezan / grace.vtc
Created August 11, 2017 14:49
Setting grace from the backend
varnishtest "Setting grace from the backend"
server s1 {
rxreq
txresp -hdr "Cache-Control: max-age=60, stale-while-revalidate=15"
} -start
varnish v1 -vcl+backend {
sub vcl_backend_response {
set beresp.http.X-ttl = beresp.ttl;
@rezan
rezan / log.vtc
Created August 16, 2017 18:45
VTC checking for a log line
varnishtest "Test log"
server s1 -repeat 2 {
rxreq
txresp
} -start
varnish v1 -vcl+backend {
import ${vmod_std};
@rezan
rezan / grace.vtc
Last active August 31, 2017 22:38
Conditional grace turns into HFP while still fresh
varnishtest "Conditional grace turns into HFP while obj.ttl > 0s"
server s1 -repeat 4 {
rxreq
txresp
} -start
varnish v1 -vcl+backend {
sub vcl_hit {
set req.http.X-status = "HIT";
@rezan
rezan / http_callback.vtc
Created September 1, 2017 22:22
vmod-http backend fetch
varnishtest "Test HTTP vmod Varnish callback"
server s1 {
rxreq
txresp -status 200
expect req.url == "/123"
expect req.http.Test1 == "2"
rxreq
txresp -status 200
@rezan
rezan / edge_json.vcl
Created October 20, 2017 19:42
Edge Logic: Securing Varnish with per user JSON data
// Edge Logic: Securing Varnish with per user JSON data
// https://info.varnish-software.com/blog/securing-varnish-plus-with-user-json-data
vcl 4.0;
backend default
{
.host = "content.company.com";
.port = "80";
}
@rezan
rezan / modified.vtc
Created November 17, 2017 13:11
Do not update an object which is older than whats in cache
varnishtest "Do not cache stale Last Modified"
server s1 {
rxreq
txresp -hdr "Last-Modified: Wed, 27 Apr 2016 14:05:52 GMT" -hdr "Version: 1"
rxreq
txresp -hdr "Last-Modified: Wed, 27 Apr 2016 16:05:52 GMT" -hdr "Version: 2"
rxreq