gpt4 book ai didi

varnish - 在线 C Varnish (VCL_deliver)

转载 作者:行者123 更新时间:2023-12-01 06:12:47 25 4
gpt4 key购买 nike

我正在使用 Varnish 4.0。

我的后端正在向某些响应添加一个 http header “x-count”

我想用换行符将“x-count”的值记录到一个文件中。

我认为我应该在 VCL 交付中完成它。

这是我目前所拥有的:

sub vcl_deliver {

if (resp.http.x-count-this:) {
set resp.http.X-infodbg = "xx";
C{
FILE *fp;
fp = fopen("/tmp/test.txt", "w+");
fputs(VRT_GetHdr(sp, HDR_OBJ, "\013x-count-this:"), fp);
fputs("\n", fp);
fclose(fp);
}C
}
}

当然它不起作用,并且有几个错误..

./vcl.gK2lu7uM.c: In function ‘VGC_function_vcl_deliver’: ./vcl.gK2lu7uM.c:1049:22: error: ‘sp’ undeclared (first use in this function) ./vcl.gK2lu7uM.c:1049:22: note: each undeclared identifier is reported only once for each function it appears in ./vcl.gK2lu7uM.c:1049:5: error: passing argument 2 of ‘VRT_GetHdr’ makes pointer from integer without a cast [-Werror] ./vcl.gK2lu7uM.c:330:7: note: expected ‘const struct gethdr_s *’ but argument is of type ‘int’ ./vcl.gK2lu7uM.c:1049:5: error: too many arguments to function ‘VRT_GetHdr’ ./vcl.gK2lu7uM.c:330:7: note: declared here

我不得不说我只是从一些示例中复制/粘贴了“sp”,但我不知道它来自哪里(我想内联 C 在不同的上下文中,因此它是在那里声明的,但不是在 vcl_deliver 中声明的)

最佳答案

因此,上述示例中 Varnish 4 和 3 之间可能未记录的差异是:

  • VRT_GetHdr 现在是 VRT_GetHdr(context, struct gethdr_s)
  • sp不存在,但有一个“ctx”变量

找到这个,那里:

http://jan.bogutzki.de/Artikel/395/set-ttl-in-varnish-4.html

   char *stuffid;
const struct gethdr_s hdr = { HDR_BERESP, "\015x-count-this:" };
stuffid = VRT_GetHdr(ctx, &hdr);

现在情况不同了:只要后端发回“count-this”,Varnish 就会崩溃,但那是另一个问题 :p(可能是我蹩脚的 C 代码)

关于varnish - 在线 C Varnish (VCL_deliver),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25688448/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com