Varnish Imgdata Module
C Shell
Latest commit 4124120 Jul 27, 2014 @webcarrot fix example bug
Permalink
Failed to load latest commit information.
src bugs Jul 26, 2014
LICENCE final initial commit Jul 26, 2014
Makefile.am first bug commit Jul 26, 2014
README.rst fix example bug Jul 27, 2014
autogen.sh first bug commit Jul 26, 2014
configure.ac first bug commit Jul 26, 2014

README.rst

vmod_imgdata

Varnish Imgdata Module

Author: Wojciech Wierchola <admin@webcarrot.pl>
Date: 2014-07-26
Version: 0.1
Manual section:3

SYNOPSIS

Basically based on Aivars Kalvans libvmod-rewrite.

Using CURL to download images and GNU coreutils base64 implementation.

DESCRIPTION

Varnish vmod that replace images urls with

"data:image/{EXT};base64,{IMAGE_DATA}".

Imgdata is performed only once and the rewritten document is stored in cache.

FUNCTIONS

imgdata_re

Prototype
imgdata_re(STRING POSTFIX_REGEX)
Return value
VOID
Description
Replace all parts of document matching
"https?://[^"' ]+\.(jpg|jpeg|png|gif){POSTFIX_REGEX}"
with
"data:image/{EXT};base64,{IMAGE_DATA}"

INSTALLATION

Usage:

./configure VARNISHSRC=DIR [VMODDIR=DIR]

VARNISHSRC is the directory of the Varnish source tree for which to compile your vmod. Both the VARNISHSRC and VARNISHSRC/include will be added to the include search paths for your module.

Optionally you can also set the vmod install directory by adding VMODDIR=DIR (defaults to the pkg-config discovered directory from your Varnish installation).

Make targets:

  • make - builds the vmod
  • make install - installs your vmod in VMODDIR

In your VCL you could then use this vmod along the following lines:

import imgdata;

sub vcl_deliver {
    if (
        resp.http.Content-Type ~ "text/html" ||
        resp.http.Content-Type ~ "text/css"  ||
        resp.http.Content-Type ~ "application/json"
    ) {
        imgdata.imgdata_re("\?inline=true");
    }
}

TODO

  • Database/cache for base64 form of images
  • Output compression
  • Output content buffer updates optimization

COPYRIGHT

Wojciech Wierchola 2014

See LICENCE (GPLv3) for details.