[prev in list] [next in list] [prev in thread] [next in thread] 

List:       varnish-misc
Subject:    regsub() odd behaviour in varnish-3.0.4-r2 on ubuntu-14.04 LTS
From:       psihozefir <psihozefir () yahoo ! com>
Date:       2015-07-15 6:12:30
Message-ID: 727596253.1296993.1436940750536.JavaMail.yahoo () mail ! yahoo ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Hello!
I run a varnish installation and I encountered an odd behaviour when trying to get a \
cookie and its value using regsub(); here is the code: vcl_hash() \
{[...]hash_data(regsub(req.http.cookie,"(LoggedIn=[^;]+;)","\1"));[...]return(hash) }
The LoggedIn cookie takes integer values depending on the user type and there are \
multiple user types (or groups).The regex should match only the cookie name, followed \
by the equal sign, followed by the user type value and finally followed by semicolon \
and then return the matched string. What varnish does instead is it returns an \
arbirarily truncated cookie:56 Hash                 c \
ASP.NET_SessionId=piejvbp31o4cbdsbzak55j2c; LoggedIn=0; __utma=203440913.1436939550.; \
__utmb=203440913.; __utmc=20913; \
__utmz=203440913..utmcsr=(direct)|utmccn=(direct)|utmcmd=(none) (Note: I manually \
truncated/edited __utm* cookies' values intentionally.) What am I doing wrong, or \
what should I know more about regsub() to be able to return the intended string?I \
tested the regex on regex101.com and it works correctly there. Thank you for your \
help!Sorin.


[Attachment #5 (text/html)]

<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, \
Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:12px"><div \
id="yui_3_16_0_1_1436938466343_12037">Hello!</div><div \
id="yui_3_16_0_1_1436938466343_12118"><br></div><div \
id="yui_3_16_0_1_1436938466343_12158" dir="ltr">I run a varnish installation and I \
encountered an odd behaviour when trying to get a cookie and its value using \
regsub(); here is the code:</div><div id="yui_3_16_0_1_1436938466343_12264" \
dir="ltr"><br></div><div id="yui_3_16_0_1_1436938466343_12263" dir="ltr">vcl_hash() \
{</div><div id="yui_3_16_0_1_1436938466343_12197" dir="ltr">[...]</div><div \
id="yui_3_16_0_1_1436938466343_12196" \
dir="ltr">hash_data(regsub(req.http.cookie,"(LoggedIn=[^;]+;)","\1"));</div><div \
id="yui_3_16_0_1_1436938466343_12208" dir="ltr">[...]</div><div \
id="yui_3_16_0_1_1436938466343_12265" dir="ltr">return(hash)<br></div><div \
id="yui_3_16_0_1_1436938466343_12195" dir="ltr">}</div><div \
id="yui_3_16_0_1_1436938466343_12603" dir="ltr"><br></div><div \
id="yui_3_16_0_1_1436938466343_12237" dir="ltr">The LoggedIn cookie takes integer \
values depending on the user type and there are multiple user types (or \
groups).</div><div id="yui_3_16_0_1_1436938466343_12367" dir="ltr">The regex should \
match only the cookie name, followed by the equal sign, followed by the user type \
value and finally followed by semicolon and then return the matched string.</div><div \
id="yui_3_16_0_1_1436938466343_12397" dir="ltr"><br></div><div \
id="yui_3_16_0_1_1436938466343_12396" dir="ltr">What varnish does instead is it \
returns an arbirarily truncated cookie:</div><div \
id="yui_3_16_0_1_1436938466343_12398" dir="ltr">56 \
Hash&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c \
ASP.NET_SessionId=piejvbp31o4cbdsbzak55j2c; LoggedIn=0; __utma=203440913.1436939550.; \
__utmb=203440913.; __utmc=20913; \
__utmz=203440913..utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)</div><div \
id="yui_3_16_0_1_1436938466343_12577" dir="ltr"><br></div><div \
id="yui_3_16_0_1_1436938466343_12576" dir="ltr">(Note: I manually truncated/edited \
__utm* cookies' values intentionally.)</div><div \
id="yui_3_16_0_1_1436938466343_12575" dir="ltr"><br></div><div \
id="yui_3_16_0_1_1436938466343_12574" dir="ltr">What am I doing wrong, or what should \
I know more about regsub() to be able to return the intended string?</div><div \
id="yui_3_16_0_1_1436938466343_12573" dir="ltr">I tested the regex on regex101.com \
and it works correctly there.</div><div id="yui_3_16_0_1_1436938466343_12572" \
dir="ltr"><br></div><div id="yui_3_16_0_1_1436938466343_12571" dir="ltr">Thank you \
for your help!</div><div id="yui_3_16_0_1_1436938466343_12566" \
dir="ltr">Sorin.<br></div></div></body></html>



_______________________________________________
varnish-misc mailing list
varnish-misc@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic