# # Copyright (c) 2014-2015 Carlos Abalde # # You're free to use and distribute this under terms in the # LICENSE file. # $Module synth 3 Synth VMOD DESCRIPTION =========== Simple VMOD useful to generate synthetic responses during the ``vcl_synth`` or ``vcl_backend_error`` phases. $Event init_function $Function VOID file(PRIV_CALL, STRING) Arguments path: location of a file readable by Varnish Cache. Description Does the same as the ``synthetic()`` primitive, but uses the contents of a file. Must be used during the ``vcl_synth`` or ``vcl_backend_error`` phases. Beware that files are internally cached for further usage. Cached files can be updated simply reloading the VCL. Example :: sub vcl_synth { if (resp.status == 700) { synth.file("/etc/varnish/assets/logo.png"); set resp.status = 200; set resp.reason = "OK"; set resp.http.Content-Type = "image/png"; return (deliver); } } $Function VOID template(PRIV_CALL, STRING, STRING, STRING) Arguments path: location of a template file readable by Varnish Cache. placeholders: delimited list of placeholders names and values. delimiter: character delimiting names and values in the list of placeholders. Description Does the same as the ``synthetic()`` primitive, but uses the contents of a template file. Must be used during the ``vcl_synth`` or ``vcl_backend_error`` phases. Beware that template files are internally cached for further usage. Cached template files can be updated simply reloading the VCL. Example :: sub vcl_synth { synth.file( "/etc/varnish/templates/error.html", "{{ xid }}|" + req.xid + "|{{ status }}|" + resp.status, "|"); set resp.reason = "OK"; set resp.http.Content-Type = "text/html"; set resp.status = 200; return (deliver); } $Function VOID pixel() Description Does the same as the ``synthetic()`` primitive, but uses the contents of a transparent 1px GIF image. Must be used during the ``vcl_synth`` or ``vcl_backend_error`` phases. Example :: sub vcl_synth { if (resp.status == 700) { std.log("..."); synth.pixel(); set resp.status = 200; set resp.reason = "OK"; set resp.http.Content-Type = "image/gif"; set obj.http.Cache-Control = "no-cache, no-store, must-revalidate"; set obj.http.Pragma = "no-cache"; set obj.http.Expires = "0"; return (deliver); } } $Function VOID string(STRING) Arguments value: any string value. Description Does the same as the ``synthetic()`` primitive. Must be used during the ``vcl_synth`` or ``vcl_backend_error`` phases. Example :: sub vcl_synth { synth.string("Hello world!"); set resp.status = 200; set resp.reason = "OK"; set resp.http.Content-Type = "text/plain"; return (deliver); }