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 (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 πŸ’–βœ¨πŸ¦‹