Iterate for parameter

kokoniimasu kokoniimasu at gmail.com
Fri Nov 9 05:44:21 CET 2012


Hi, All,

I'm making a new feature for vmod-parsereq.

New feature is calling VCL subroutine for each parameter(POST, GET,
COOKIE and ...)


--sample vcl (iterate for all GET parameter)
import parsereq;
import std;

sub test{
    parsereq.get_read_next();
    set req.http.hoge = req.http.hoge + parsereq.get_read_cur() + ":";
    set req.http.hoge = req.http.hoge +
parsereq.get_header(parsereq.get_read_cur());
}

sub test2{
    parsereq.get_read_next();
    set req.http.hoge2 = req.http.hoge2 + parsereq.get_read_cur() + ":";
    set req.http.hoge2 = req.http.hoge2 +
parsereq.get_header(parsereq.get_read_cur());
}

sub vcl_recv{
    parsereq.init();
    set req.http.hoge= "[start]";
    C{
        Vmod_Func_parsereq.get_read_iterate(sp, (const char*)VGC_function_test);
    }C
    set req.http.hoge = req.http.hoge + "[end]";

    set req.http.hoge2= "[start]";
    C{
        Vmod_Func_parsereq.get_read_iterate(sp, (const
char*)VGC_function_test2);
    }C
    set req.http.hoge2 = req.http.hoge2 + "[end]";


    std.syslog(6,req.http.hoge);
    std.syslog(6,req.http.hoge2);
}

-----------------------
http://192.168.1.199:6081/?x=aa&y=bb
--result
Oct 24 01:12:39 localhost varnishd[30214]: [start]y:bb x:aa [end]
Oct 24 01:12:39 localhost varnishd[30214]: [start]y:bb x:aa [end]

-----------------------
http://192.168.1.199:6081/?x=aa&y=bb&z=cc
--result
Oct 24 01:12:56 localhost varnishd[30214]: [start]z:cc y:bb x:aa [end]
Oct 24 01:12:56 localhost varnishd[30214]: [start]z:cc y:bb x:aa [end]

code:
https://github.com/xcir/libvmod-parsereq/tree/future-iterate


What do you think about this syntax?

Regards,
--
Syohei Tanaka(@xcir)
http://xcir.net/

(:3[__])



More information about the varnish-misc mailing list