2014-09-05 33 views
1

我正在使用清漆4.0。內聯C清漆(VCL_deliver)

我的後端也加入到了一些迴應的HTTP標頭「X-數」

我想的「X-數」值登錄到帶有換行符的文件。

我認爲我應該在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)

回答

4

所以在上面的實施例4清漆和3之間的大概無證區別在於:現在

  • VRT_GetHdr是VRT_GetHdr(上下文,結構gethdr_s)
  • 屬不存在,但有一個「 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); 

而現在一個不同的故事:光油作爲後端發回儘快崩潰「計數這個」,但是這是一個不同的問題:P(我蹩腳的ç大概代碼)

2

我沒有清漆4.0公頃ndy來測試這個,但我能夠讓你的例子與Varnish 3.0一起工作。當我按照原樣嘗試VCL時,我並沒有得到確切的錯誤。第一個變化:

if (resp.http.x-count-this:) { 

需要是:

if (resp.http.x-count-this) { 

冒號應當離開的標題名稱的時稱爲這種方式。下一個:

fputs(VRT_GetHdr(sp, HDR_OBJ, "\013x-count-this:"), fp); 

需要是:

fputs(VRT_GetHdr(sp, HDR_OBJ, "\015x-count-this:"), fp); 

在該字符串的長度值需要在八進制出於某種原因,並13八進制是15。做出這些改變讓這個爲我工作。話雖如此,你很多人想用openfcntl而不是fopen,因爲沒有文件鎖定我不知道多個請求爭奪該文件的效果是什麼。

+0

謝謝你,但.. 「if」中的「:」是編輯問題,但「八進制值而不是十進制」是一個很好的提示。然而,「sp」變量仍然不存在,可能是一個Varnish 3/4的東西:( – cyqui 2014-09-08 07:59:15