该 清漆文档 说,我们可以在VCL文件中包含C语言片段,如
sub vcl_hash {
C{
int i = /* Some logic to get a number */
}C
}
但现在我如何使用整数的值 i
来设置响应头,或cookie
查看 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
}
见 另一个例子
你为什么不直接用VCL?set resp.http.x-header = header
来设置任何你想设置的头。
我鼓励你直接写一个vmod,这样会更方便。你可以在这里找到一个(老的但仍然相关的)指南。https:/info.varnish-software.comlogcreating-a-vmod-vmod-str。