Upper and lower case strings in Varnish

Richard Chiswell richard.chiswell at mangahigh.com
Wed Feb 3 18:15:30 CET 2010


Hi Poul,

Poul-Henning Kamp wrote:
> In message <4B69AB1A.6010406 at mangahigh.com>, Richard Chiswell writes:
>   
>> I've got a simple question which I've been puzzling on for the last 30 
>> minutes or so - how do you change a string in Varnish to lowercase?
>>     
> You'll have to use a bit of inline C code to do that.
>   
Thanks Poul - any chance of any example of how to do this with a regular 
expression: we currently have:
set obj.http.Location = "http://" req.http.host "/" 
regsub(req.url,"^/(en_gb/|en_us/)?([A-Za-z]+)/?(.*)$","\1\2");
but we only want the \1 lowercased -I've got to
set obj.http.Location = "http://" req.http.host "/" 
regsub(req.url,"^/(en_gb/|en_us/)?([A-Za-z]+)/?(.*)$","C{char 
str[255];str=\1;for (i=0;str[i];i++) { str[i]=tolower(str[i]);return 
str;}C\2");
but that doesn't seem to work. I don't suppose you can point me in the 
right direction (it's been over 10 years since I've done C [since then 
C++, C#.Net, PHP, Perl and Java: so remembering what's valid syntax is 
bad enough, and I've got no idea about the passing to/from varnish side 
of things).

Thank you,
Richard


More information about the varnish-misc mailing list