Discussion:
Learning C and VRT_SetHdr()
Dan
2011-03-31 11:39:51 UTC
Permalink
I would like to do some more advanced functionality within our VCL file,
and to do so need to use the inline-c capabilities of varnish. So, to
start off with, I thought I would get my VCL file to set the headers, so
I can test variables, and be sure it is working. But am getting a WSOD
when I impliment my seemingly simple code.


So my main questions are:
* Are there any good docs on the VRT variables
* Are there examples/tutorials on using C within the VCL (for beginners
to the subject)
* Is there something obvious I have overlooked when writing my code


The snipper from my current code is:
/sub detectmobile {/
/ C{/
/ VRT_SetHdr(sp, HDR_BEREQ, "\020X-Varnish-TeraWurfl:", "no1",
vrt_magic_string_end);/
/ }C/
/}/
/sub vcl_miss {/
/ call detectmobile;/
/ return(fetch);/
/}/
/sub vcl_pipe {/
/ call detectmobile;/
/ return(pipe);/
/}/
/sub vcl_pass {/
/ call detectmobile;/
/ return(pass);/
/}/


Thanks for your advice,
Dan
AD
2011-03-31 11:58:26 UTC
Permalink
use -C to display the default VCL , or just put in a command you want to do
in C inside the vcl and then see how it looks when running -C -f against the
config.
Post by Dan
I would like to do some more advanced functionality within our VCL file,
and to do so need to use the inline-c capabilities of varnish. So, to start
off with, I thought I would get my VCL file to set the headers, so I can
test variables, and be sure it is working. But am getting a WSOD when I
impliment my seemingly simple code.
* Are there any good docs on the VRT variables
* Are there examples/tutorials on using C within the VCL (for beginners to
the subject)
* Is there something obvious I have overlooked when writing my code
*sub detectmobile {*
* C{*
* VRT_SetHdr(sp, HDR_BEREQ, "\020X-Varnish-TeraWurfl:", "no1",
vrt_magic_string_end);*
* }C*
*}*
*sub vcl_miss {*
* call detectmobile;*
* return(fetch);*
*}*
*sub vcl_pipe {*
* call detectmobile;*
* return(pipe);*
*}*
*sub vcl_pass {*
* call detectmobile;*
* return(pass);*
*}*
Thanks for your advice,
Dan
_______________________________________________
varnish-misc mailing list
http://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
Dan
2011-03-31 13:28:21 UTC
Permalink
Post by AD
use -C to display the default VCL , or just put in a command you want
to do in C inside the vcl and then see how it looks when running -C -f
against the config.
I would like to do some more advanced functionality within our VCL
file, and to do so need to use the inline-c capabilities of
varnish. So, to start off with, I thought I would get my VCL file
to set the headers, so I can test variables, and be sure it is
working. But am getting a WSOD when I impliment my seemingly
simple code.
* Are there any good docs on the VRT variables
* Are there examples/tutorials on using C within the VCL (for
beginners to the subject)
* Is there something obvious I have overlooked when writing my code
/sub detectmobile {/
/ C{/
/ VRT_SetHdr(sp, HDR_BEREQ, "\020X-Varnish-TeraWurfl:", "no1",
vrt_magic_string_end);/
/ }C/
/}/
/sub vcl_miss {/
/ call detectmobile;/
/ return(fetch);/
/}/
/sub vcl_pipe {/
/ call detectmobile;/
/ return(pipe);/
/}/
/sub vcl_pass {/
/ call detectmobile;/
/ return(pass);/
/}/
Thanks for your advice,
Dan
_______________________________________________
varnish-misc mailing list
http://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
Sorry, I am confused, where would I put -C, in my /etc/default/varnish
file? Is this required to use inline-c within my vcl file?
thebog
2011-03-31 19:46:33 UTC
Permalink
I think he meant -C in the commandline. Not inside the file.

YS
Anders Berg
Post by AD
use -C to display the default VCL , or just put in a command you want to do
in C inside the vcl and then see how it looks when running -C -f against the
config.
Post by Dan
I would like to do some more advanced functionality within our VCL file,
and to do so need to use the inline-c capabilities of varnish.  So, to start
off with, I thought I would get my VCL file to set the headers, so I can
test variables, and be sure it is working.  But am getting a WSOD when I
impliment my seemingly simple code.
* Are there any good docs on the VRT variables
* Are there examples/tutorials on using C within the VCL (for beginners to
the subject)
* Is there something obvious I have overlooked when writing my code
sub detectmobile {
  C{
    VRT_SetHdr(sp, HDR_BEREQ, "\020X-Varnish-TeraWurfl:", "no1",
vrt_magic_string_end);
  }C
}
sub vcl_miss {
  call detectmobile;
  return(fetch);
}
sub vcl_pipe {
  call detectmobile;
  return(pipe);
}
sub vcl_pass {
  call detectmobile;
  return(pass);
}
Thanks for your advice,
Dan
_______________________________________________
varnish-misc mailing list
http://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
Sorry, I am confused, where would I put -C, in my /etc/default/varnish
file?  Is this required to use inline-c within my vcl file?
_______________________________________________
varnish-misc mailing list
http://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
Cosimo Streppone
2011-03-31 11:58:54 UTC
Permalink
Is it correct to do this in all
vcl_miss, pipe and pass?
What about vcl_hit then?

I would have expected this to happen in vcl_deliver()
or vcl_fetch() if you want your backends to see
the header you're setting.

Anyway...
Post by Dan
/sub detectmobile {/
/ C{/
/ VRT_SetHdr(sp, HDR_BEREQ, "\020X-Varnish-TeraWurfl:", "no1",
vrt_magic_string_end);/
/ }C/
I believe you have a problem in the "\020" bit.
That is octal notation.

"X-Whatever:" is 11 bytes, including the ':',
so you need to write:

"\013X-Whatever:"

Have fun,
--
Cosimo
Dan
2011-03-31 13:25:13 UTC
Permalink
Post by Cosimo Streppone
Is it correct to do this in all
vcl_miss, pipe and pass?
What about vcl_hit then?
I would have expected this to happen in vcl_deliver()
or vcl_fetch() if you want your backends to see
the header you're setting.
Anyway...
Post by Dan
/sub detectmobile {/
/ C{/
/ VRT_SetHdr(sp, HDR_BEREQ, "\020X-Varnish-TeraWurfl:", "no1",
vrt_magic_string_end);/
/ }C/
I believe you have a problem in the "\020" bit.
That is octal notation.
"X-Whatever:" is 11 bytes, including the ':',
"\013X-Whatever:"
Have fun,
Sadly no luck with that, I have ammended my code as recommended.
Varnish is still able to restart without errors, but WSOD on page load.
My custom function is now something:

sub detectmobile {
C{
VRT_SetHdr(sp, HDR_BEREQ, "\013X-Varnish-TeraWurfl:", "no1",
vrt_magic_string_end);
}C
}

And the only occurance of 'call detectmobile;' is in:
sub vcl_deliver {}

Are there any libraries required for the VRT scripts to work?

Do I need to alter the /etc/varnish/default file for C to work in varnish?
Ken Brownfield
2011-03-31 18:09:24 UTC
Permalink
Sadly no luck with that, I have ammended my code as recommended. Varnish
is still able to restart without errors, but WSOD on page load. My custom
The length of your header is 20 characters including the colon. 013 is the
length (in octal) of the X-Whatever: example provided to explain this to
you, it is not octal for 20. Replace 013 with 024 to avoid segfaults.
There are docs covering this on the website, BTW.

What on earth is a WSOD?
--
kb
sub detectmobile {
C{
VRT_SetHdr(sp, HDR_BEREQ, "\013X-Varnish-TeraWurfl:", "no1",
vrt_magic_string_end);
}C
}
sub vcl_deliver {}
Are there any libraries required for the VRT scripts to work?
Do I need to alter the /etc/varnish/default file for C to work in varnish?
_______________________________________________
varnish-misc mailing list
http://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
Loading...