vmod_accept(3)
π vmod_accept β the Accept VMOD π
okay so bestie, this is vmod_accept(3) from the Library Functions Manual, and it's literally the glow-up your Accept* headers have been waiting for π
β¨ SYNOPSIS β¨
import accept [as name] [from "path"]
new xrule = accept.rule(STRING string)
VOID xrule.add(STRING string)
VOID xrule.remove(STRING string)
STRING xrule.filter(STRING string)
πΈ DESCRIPTION πΈ
so accept lets you sanitize the Accept* headers (mainly Accept, Accept-Charset and Accept-Encoding) by specifying one fallback string, and then adding valid values on top. it's giving bodyguard for your headers, fr fr π
sub vcl_init {
new rule = accept.rule("text/plain");
rule.add("text/html");
rule.add("application/json");
}
then you take that rule object and use it to filter the headers. the following line will set the accept header to "text/html" or "application/json" if any of them is found in the original header, and will set it to "text/plain" if neither is found:
sub vcl_recv {
set req.http.Accept = rule.filter(req.http.Accept);
}
accept will ignore any parameter found and will just return the first choice found. more info here: <https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html> β iykyk π
π API π
π¦ new xrule = accept.rule(STRING string)
create a rule object, setting the fallback string. this is your main character moment, the rule is born β¨
π¦ VOID xrule.add(STRING string)
add string to the list of valid choices. yes queen, expand your options π
π¦ VOID xrule.remove(STRING string)
remove string to the list of valid choices. okay so the original literally says "remove string to the list" β that's the wording, not me being chaotic π«Ά
π¦ STRING xrule.filter(STRING string)
parse string and try to find a valid choice. the first one found is returned (they are tested in the same order they were added), otherwise, the fallback string is returned. lowkey iconic behavior ngl π
π COPYRIGHT π
Copyright (c) 2016 Guillaume Quintard
Author: Guillaume Quintard <guillaume.quintard@gmail.com>
(vmodtool requires this format.)
yes bestie, (vmodtool requires this format.) is a real line in the original. the tool said so. periodt π
and that's the whole page π this was vmod_accept(3), living in the Library Functions Manual β mwah, tysm for reading, go sanitize those headers bestie πβ¨π¦
π¦ where this page comes from
- fedora 44: varnish-modules 0.27.0-2.fc44 Β· BSD-2-Clause
- fedora 44: varnish-modules 0.27.0-4.fc44 Β· BSD-2-Clause
- nixos 26.05: varnish 8.0.2-modules-0.27.0
- ubuntu resolute: varnish-modules 0.26.0-2build1 Β· BSD-2-Clause
- ubuntu stonking: libvmod-modules 0.28.0-4 Β· BSD-2-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms