Problems with Varnish-LUA integration.

Nishant Trivedi Nishant.Trivedi at dictionary.com
Mon May 9 20:26:38 CEST 2016


Hello,

I am trying to use Varnish in one of my projects and I need to parse some JSON and make some decisions as part of the design. Since Varnish supports LUA I decided to do the parsing and decision making in LUA. I am using libvmod-lua<https://github.com/flygoast/libvmod-lua> to invoke LUA scripts from Varnish. I setup a container with Apache2, Varnish 4.1, LUA 5.1.5, and LUARocks 2.3.0 along with all the dependencies. I then installed libvmod-lua in the container. I changed the default.vcl file to look like this:
# Marker to tell the VCL compiler that this VCL has been adapted to the
# new 4.0 format.
vcl 4.0;

import lua;
import std;

# Default backend definition. Set this to point to your content server.
backend default {
    .host = "127.0.0.1";
    .port = "8080";
}

sub vcl_recv {
    lua.init("/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua;/usr/local/lib/lua/5.1/?.lua;/usr/local/lib/lua/5.1/?/init.lua",
             "/usr/local/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/loadall.so",
             "/my/foo.lua");
}

sub vcl_deliver {
    set resp.http.x-json = lua.call("test_json");
    set resp.http.x-now = lua.call("test_now");
    return (deliver);
}
And following are the contents of foo.lua:
local cjson = require("cjson")

function test_json()
    local t = {}
    t[1] = "hello"
    t[2] = "world"
    return cjson.encode(t)
end

function test_now()
    return 1234
end

But when I curl localhost:80 the x-json and x-now headers show up as empty in the response. I was wondering if I am missing something in the setup. I ran the LUA script independently and made sure its returning the right thing. I would appreciate any help on this issue.

Also wanted to note that libvmod-lua doesn’t compile with LUA 5.3.2 which is the latest version of LUA. Are there plans to update the vmod?

Thanks,
—
Nishant.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20160509/1bb4ede0/attachment.html>


More information about the varnish-misc mailing list