Efficient JSON parsing in VCL with the frozen parser (see https://github.com/cesanta/frozen)
For issues & merge requests please use the gitlab mirror: https://gitlab.com/uplex/varnish/libvmod-frozen
Before that, when building from a system without Git some Makefile steps would fail because without it vmodtool.py would not generate the required src/vmod_vcs_version.txt file to be present. We now check if the file is already present or if git is installed, if either condition is validated then src/vmod_vcs_version.txt will be used, if not it will not be used and a warning will be issued at configure time. |
||
|---|---|---|
| examples/jwt | ||
| src | ||
| .clang-tidy | ||
| .gitignore | ||
| .gitlab-ci.yml | ||
| .gitmodules | ||
| bootstrap | ||
| configure.ac | ||
| INSTALL.rst | ||
| LICENSE | ||
| Makefile.am | ||
| README.rst | ||
===========
vmod_frozen
===========
---------------------
Varnish frozen Module
---------------------
DESCRIPTION
===========
This vmod makes available to VCL the _frozen_ JSON parser with low
overhead: By specifying a set of expected JSON paths, a callback to
the parser is used to track only paths of interest, which can then be
extracted.
Example
::
import frozen;
sub vcl_init {
new jwt_hdr = frozen.parser();
jwt_hdr.expect(".alg", type=STRING, null=false, required=true);
jwt_hdr.expect(".typ", type=STRING, null=false, required=true);
new jwt_payload = frozen.parser();
jwt_payload.expect(".attr");
}
sub vcl_recv {
if (! jwt_hdr.parse(...) ||
jwt_hdr.extract(".alg") != "RS256" ||
jwt_hdr.extract(".typ") != "JWT") {
return (synth(400, "unsupported jwt alg/typ"));
}
if (! jwt_payload.parse(...)) {
return (synth(400, "parse error"));
}
set req.http.something =
jwt_payload.extract(".attr",
null = "<null>", undef = "<undef>");
# ...
}
INSTALLATION
============
See `INSTALL.rst <INSTALL.rst>`_ in the source repository.
SEE ALSO
========
* vcl(7)
* varnishd(1)
COPYRIGHT
=========
::
Copyright 2018 UPLEX Nils Goroll Systemoptimierung
All rights reserved
Author: Nils Goroll <nils.goroll@uplex.de>
See LICENSE