Search code examples
varnishvarnish-vcl

Upgrade to varnish v4


We've upgraded varnish v3 to v4 and I currently working on converting my vcl.

In the v3 version we've used inline C to set and read headers with following functions:

VRT_GetHdr(sp, HDR_REQ, header);    
VRT_SetHdr(sp, HDR_REQ, header, value , vrt_magic_string_end);

However in version 4 those functions are are slighty changed. After some searching we've found that's we need to use a kind of a structure to define a header.

VCL_HEADER hdrdef;
hdrdef->where = HDR_REQ;
hdrdef->what = "\005Test:";

When using this we get a compiler fail with message that it cannot assign to a read only object. Do somebody know how we can utilize/fill this structure?

Thanks in advance!

Kristof


Solution

  • This should do the trick:

    C{
    static const struct gethdr_s VGC_HDR_REQ_hdrdef = { HDR_REQ, "\005Test:" };
    }C
    
    C{
    VRT_SetHdr(ctx, &VGC_HDR_REQ_hdrdef, value, vrt_magic_string_end);
    }C
    

    See: https://github.com/varnish/Varnish-Cache/blob/master/bin/varnishtest/tests/r01406.vtc