Re: Upper and lower case strings in Varnish
On 3 February 2010 17:15, Richard Chiswell wrote: >> Hi Poul, >> >> Poul-Henning Kamp wrote: >>> In message <4b69ab1a.6010...@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. I'm no varnish or C expert, YMMV etc... but I managed to get something like this working. It's a VCL with embedded C that reads the "Accept-Language" header and rewrites it (or writes into a different header, actually) the result of some processing function. Take a look at the examples here: http://github.com/cosimo/varnish-accept-language/tree/master/examples sample.vcl is the main VCL file, from which you embed the other one, accept-language.vcl, which in turn contains the C function you want to use. I think `vcl_rewrite_accept_language()' is what you need. Then you're only missing the upper->lower case bit. -- Cosimo ___ varnish-misc mailing list varnish-misc@projects.linpro.no http://projects.linpro.no/mailman/listinfo/varnish-misc
Re: Upper and lower case strings in Varnish
I don't think it's possible to write a regex that will do that in one go. There's a dumb solution though: set obj.http.Location regsuball(obj.http.Location, "A", "a"); set obj.http.Location regsuball(obj.http.Location, "B", "b"); ... Laurence On 3 February 2010 17:15, Richard Chiswell wrote: > Hi Poul, > > Poul-Henning Kamp wrote: >> In message <4b69ab1a.6010...@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 > ___ > varnish-misc mailing list > varnish-misc@projects.linpro.no > http://projects.linpro.no/mailman/listinfo/varnish-misc > ___ varnish-misc mailing list varnish-misc@projects.linpro.no http://projects.linpro.no/mailman/listinfo/varnish-misc
Re: Upper and lower case strings in Varnish
Hi Poul, Poul-Henning Kamp wrote: > In message <4b69ab1a.6010...@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 ___ varnish-misc mailing list varnish-misc@projects.linpro.no http://projects.linpro.no/mailman/listinfo/varnish-misc
Re: Upper and lower case strings in Varnish
In message <4b69ab1a.6010...@mangahigh.com>, Richard Chiswell writes: >Hi all, > >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? > >Basically, all the links on our site should be lowercase, but some >people have been randomly capitalising them when linking to them - I'd >just like Varnish to issue a 301 redirect to the lowercased version of >the URL: everything is in place apart from converting the string to >lowercase. You'll have to use a bit of inline C code to do that. Poul-Henning -- Poul-Henning Kamp | UNIX since Zilog Zeus 3.20 p...@freebsd.org | TCP/IP since RFC 956 FreeBSD committer | BSD since 4.3-tahoe Never attribute to malice what can adequately be explained by incompetence. ___ varnish-misc mailing list varnish-misc@projects.linpro.no http://projects.linpro.no/mailman/listinfo/varnish-misc