内联 C 清漆 (VCL_deliver) [英] Inline C Varnish (VCL_deliver)

查看:28
本文介绍了内联 C 清漆 (VCL_deliver)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Varnish 4.0.

I am using Varnish 4.0.

我的后端正在向一些响应添加一个 http 标头x-count"

My backend is adding to some responses an http header "x-count"

我想用换行符将x-count"的值记录到文件中.

I would like to log the value of "x-count" into a file with a line break.

我认为我应该使用 VCL 交付.

I assumed i should do it in VCL deliver.

这是我目前所拥有的:

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
    }
}

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

Of course it doesnt work and there is a couple of errors ..

./vcl.gK2lu7uM.c:在函数‘VGC_function_vcl_deliver’中:./vcl.gK2lu7uM.c:1049:22: error: ‘sp’ undeclared (第一次使用在这个函数)./vcl.gK2lu7uM.c:1049:22:注意:每个未声明的标识符对于它出现的每个函数只报告一次./vcl.gK2lu7uM.c:1049:5: 错误:传递‘VRT_GetHdr’的参数 2从整数创建指针而不进行强制转换 [-Werror]./vcl.gK2lu7uM.c:330:7:注意:预期的‘const struct gethdr_s *’但是参数的类型为‘int’ ./vcl.gK2lu7uM.c:1049:5: 错误:太多函数‘VRT_GetHdr’的参数./vcl.gK2lu7uM.c:330:7:注意:在这里声明

./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 中声明)

I have to say that i simply copy/pasted "sp" from some examples, but i have no idea where it comes from (i suppose the inline C was in a different context and therefore it was declared there but not in vcl_deliver)

推荐答案

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

So the probably undocumented differences between Varnish 4 and 3 in the above examples are :

  • 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 代码)

And now a different story: Varnish is crashing as soon as the backend sends back "count-this", but that is a different problem :p (my crappy C code probably)

这篇关于内联 C 清漆 (VCL_deliver)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆