在VCL中使用C语言修改响应

问题描述 投票:0回答:1

清漆文档 说,我们可以在VCL文件中包含C语言片段,如

sub vcl_hash {
    C{
            int i = /* Some logic to get a number */
    }C
}

但现在我如何使用整数的值 i 来设置响应头,或cookie

c varnish-vcl varnish-4
1个回答
1
投票

查看 varnish.vcc

和功能。

在清漆4中,有 ctx 为上下文定义的variabl(相对于 sp 在清漆3)(源头)

例如:

sub vcl_hash {
    C{
        const char *hash = calc_hash(...);
        const struct gethdr_s hdr = { 
            HDR_BERESP,
            "\010X-Hash:" // length prefixed string, in octal 
        };
        VRT_SetHdr(ctx, &hdr, hash, vrt_magic_string_end);
    }C
}

另一个例子


0
投票

你为什么不直接用VCL?set resp.http.x-header = header 来设置任何你想设置的头。


0
投票

我鼓励你直接写一个vmod,这样会更方便。你可以在这里找到一个(老的但仍然相关的)指南。https:/info.varnish-software.comlogcreating-a-vmod-vmod-str。

© www.soinside.com 2019 - 2024. All rights reserved.