Last active
February 19, 2021 01:04
-
-
Save DanielThomas/cdbbc12665534cce785c05a4c407bcce to your computer and use it in GitHub Desktop.
Varnish Cache Plus (Enterprise) configuration for Gradle HTTP Build Cache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vcl 4.1; | |
import purge; | |
import std; | |
import synthbackend; | |
sub vcl_recv { | |
if (req.method != "GET" && req.method != "PUT" && req.method != "DELETE") { | |
return (synth(405)); | |
} | |
if (req.url !~ "^/cache/[^/]*$") { | |
return (synth(404)); | |
} | |
if (req.method == "PUT") { | |
if (req.http.user-agent !~ "^Gradle") { | |
return (synth(400)); | |
} | |
if (req.http.content-type !~ "^application/vnd.gradle.build-cache-artifact") { | |
return (synth(415)); | |
} | |
if (req.http.content-length) { | |
// In later releases | |
// if (std.bytes(req.http.content-length) > 10MB) { | |
if (std.integer(req.http.content-length, 0) > 10485760) { | |
return (synth(413)); | |
} | |
} else if (!std.cache_req_body(10MB)) { | |
return (synth(413)); | |
} | |
set req.http.put-method = true; | |
return (hash); | |
} | |
return (hash); | |
} | |
sub vcl_synth { | |
return (deliver); | |
} | |
sub vcl_hit { | |
if (req.http.put-method) { | |
return (synth(200)); | |
} | |
} | |
sub vcl_miss { | |
if (req.method == "GET") { | |
return (synth(404)); | |
} | |
} | |
sub vcl_backend_fetch { | |
if (bereq.http.put-method) { | |
set bereq.method = "PUT"; | |
set bereq.backend = synthbackend.mirror(); | |
return (fetch); | |
} | |
} | |
sub vcl_backend_response { | |
set beresp.ttl = 30d; | |
set beresp.grace = 0s; | |
set beresp.keep = 0s; | |
set beresp.http.Content-Type = bereq.http.Content-Type; | |
} | |
sub vcl_deliver { | |
if (req.http.put-method) { | |
return (synth(201)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment