Mailing List Archive

varnish & cookies & multilanguage
Hello,
I'm new to varnish and i have some problems with cookies.
I have to cache a website who use coookies to determine the language.

The cookies are:
15 TxHeader b Cookie: _ZopeId="23273311A29b-he1CIg"; LOCALIZER_LANGUAGE="es"

The url used to change language on the website is like that:
http://xxxx?lang=en
So i made this :

if (req.url ~ "=(en|es|de|fr|it|pt|pl|ru|el|ko|zh-CN|zh|ja|ar)$"){
pipe;
}
But it didn't solve the problem.

The only way i found is :
if (req.http.Cookie ~ "LOCALIZER_LANGUAGE") {
pipe;
}
Adn it works fine but now, nothing is cached :(

So my question :)
Is there's a way to cache a website like this, using cookies for language?

Thx in advance,
rafailowski
varnish & cookies & multilanguage [ In reply to ]
In message <8e6064260708020220q2ae3fe98ia3fcb9d0a6f186b4 at mail.gmail.com>, rafailowski writes
:
>Hello,
>I'm new to varnish and i have some problems with cookies.
>I have to cache a website who use coookies to determine the language.
>
>The cookies are:
>15 TxHeader b Cookie: _ZopeId="23273311A29b-he1CIg"; LOCALIZER_LANGUAGE="es"

>Is there's a way to cache a website like this, using cookies for language?

I can think of one way that might work:

Hash that part of the cookie in addition to the URL and host, something like:

vcl_hash {
if (req.http.cookie) {
set req.hash += regsub(
req.http.cookie,
".*LOCALIZER_LANGUAGE=\"(..)\".*",
"$1");
}
}

(If this work, please take a moment to add it to our FAQ!)

--
Poul-Henning Kamp | UNIX since Zilog Zeus 3.20
phk at 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 & cookies & multilanguage [ In reply to ]
2007/8/2, Poul-Henning Kamp <phk at phk.freebsd.dk>:
> In message <8e6064260708020220q2ae3fe98ia3fcb9d0a6f186b4 at mail.gmail.com>, rafailowski writes
> :
> >Hello,
> >I'm new to varnish and i have some problems with cookies.
> >I have to cache a website who use coookies to determine the language.
> >
> >The cookies are:
> >15 TxHeader b Cookie: _ZopeId="23273311A29b-he1CIg"; LOCALIZER_LANGUAGE="es"
>
> >Is there's a way to cache a website like this, using cookies for language?
>
> I can think of one way that might work:
>
> Hash that part of the cookie in addition to the URL and host, something like:
>
> vcl_hash {
> if (req.http.cookie) {
> set req.hash += regsub(
> req.http.cookie,
> ".*LOCALIZER_LANGUAGE=\"(..)\".*",
> "$1");
> }
> }
>
> (If this work, please take a moment to add it to our FAQ!)
>
> --
> Poul-Henning Kamp | UNIX since Zilog Zeus 3.20
> phk at 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.
>
> vcl_hash {
> if (req.http.cookie) {
> set req.hash += regsub(
> req.http.cookie,
> ".*LOCALIZER_LANGUAGE=\"(..)\".*",
> "$1");
> }
> }

There's a little problem with these regexp
".*LOCALIZER_LANGUAGE=\"(..)\".*",
At the second \ ,varnish returns a "Syntax error".
I've tried different things around with regexp but i can't make it run.
What's wrong ?
varnish & cookies & multilanguage [ In reply to ]
"Poul-Henning Kamp" <phk at phk.freebsd.dk> writes:
> Hash that part of the cookie in addition to the URL and host, something like:
>
> vcl_hash {
> if (req.http.cookie) {
> set req.hash += regsub(
> req.http.cookie,
> ".*LOCALIZER_LANGUAGE=\"(..)\".*",
> "$1");
> }
> }
>
> (If this work, please take a moment to add it to our FAQ!)

shouldn't

vcl_hash {
req.hash += req.http.cookie[LOCALIZER_LANGUAGE];
}

work, or haven't you implemented subscripting yet?

DES
--
Dag-Erling Sm?rgrav
Senior Software Developer
Linpro AS - www.linpro.no
varnish & cookies & multilanguage [ In reply to ]
In message <8e6064260708020702w541c5c70t7088de0c0ff205a at mail.gmail.com>, rafailowski writes:


>There's a little problem with these regexp
>".*LOCALIZER_LANGUAGE=\"(..)\".*",
>At the second \ ,varnish returns a "Syntax error".

Yeah, I'm forgetting that I tried to make it easier for webmasters :-)

Try using %22 instead of \"

".*LOCALIZER_LANGUAGE=%22(..)%22.*"

--
Poul-Henning Kamp | UNIX since Zilog Zeus 3.20
phk at 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 & cookies & multilanguage [ In reply to ]
In message <ujrmyxa80du.fsf at false.linpro.no>, =?iso-8859-1?Q?Dag-Erling_Sm=F8rgrav?= writes:
>"Poul-Henning Kamp" <phk at phk.freebsd.dk> writes:

>shouldn't
>
>vcl_hash {
> req.hash +=3D req.http.cookie[LOCALIZER_LANGUAGE];
>}
>
>work, or haven't you implemented subscripting yet?

Not implemented yet.

--
Poul-Henning Kamp | UNIX since Zilog Zeus 3.20
phk at 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 & cookies & multilanguage [ In reply to ]
It doesn't work with this:

sub vcl_hash {
if (req.http.cookie) {
set req.hash += regsub(
req.http.cookie,
".*LOCALIZER_LANGUAGE=%22(..)%22.*",
"$1");
}
}

So i investiguate the logs and i found this, it seems that it crash
the process childs.
with %22.

here's the varnish logs:
0 CLI Rd vcl.use boot
0 CLI Wr 0 200
0 CLI Rd start
0 CLI Wr 0 200
0 WorkThread 0xb43e3830 start
12 SessionOpen c 72.18.0.221 35046
0 CLI Rd vcl.load boot ./bin.XXvU36Ya
0 CLI Wr 0 200 Loaded "./bin.XXvU36Ya" as "boot"

0 CLI Rd vcl.use boot
0 CLI Wr 0 200
0 CLI Rd start
0 CLI Wr 0 200
0 WorkThread 0xb41fd830 start
12 SessionOpen c 72.18.0.221 35047
0 CLI Rd vcl.load boot ./bin.XXvU36Ya
0 CLI Wr 0 200 Loaded "./bin.XXvU36Ya" as "boot"

0 CLI Rd vcl.use boot
0 CLI Wr 0 200
0 CLI Rd start
0 CLI Wr 0 200
0 WorkThread 0xb43e3830 start
12 SessionOpen c 72.18.0.221 35048
0 CLI Rd vcl.load boot ./bin.XXvU36Ya
0 CLI Wr 0 200 Loaded "./bin.XXvU36Ya" as "boot"

How can i fix this? Do you need more infos and which one to solve this
another problem :)
Thx
varnish & cookies & multilanguage [ In reply to ]
In message <8e6064260708020912ld274f18n7fea9f636dd6a31 at mail.gmail.com>, rafailowski writes:
>It doesn't work with this:
>
>sub vcl_hash {
> if (req.http.cookie) {
> set req.hash += regsub(
> req.http.cookie,
> ".*LOCALIZER_LANGUAGE=%22(..)%22.*",
> "$1");
> }
>}
>
>So i investiguate the logs and i found this, it seems that it crash
>the process childs.

It's not the %22 that causes the crash, it is a memory management
issue, and I don't have a 4 minute fix right now, I've opened a
ticket and will look at it.

You may be able to work around this for now by doing the substitution
into a pseudo header in vcl_recv and use that in vcl_hash, something like:

sub vcl_recv {
[...]
if (req.http.cookie ~ LOCALIZER_LANGUAGE) {
set req.http.mylang = regsub(
req.http.cookie,
".*LOCALIZER_LANGUAGE=%22(..)%22.*",
"$1");
lookup;
}
[...]
}


sub vcl_hash {
set req.hash += req.http.mylang;
}



--
Poul-Henning Kamp | UNIX since Zilog Zeus 3.20
phk at 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 & cookies & multilanguage [ In reply to ]
Hello, just a (late!) feed back...
It's works really fine.

sub vcl_recv {
if (req.http.cookie ~ "LOCALIZER_LANGUAGE") {
set req.http.mylang = regsub(
req.http.cookie,
".*LOCALIZER_LANGUAGE=%22(..)%22.*",
"$1");
lookup;
}
[...]
lookup;
}

sub vcl_hash {
set req.hash += req.http.mylang;
}

Thanks again :)