AnyEvent::HTTP and "bad" cookies
José Micó
jose.mico at gmail.com
Sun Jun 20 10:23:04 CEST 2010
Just hoping to contribute, I tried to fix to the parser regexp. Then, I
noted some issues:
1. Unquoted expires dates with commas are fairly common, and the regexp
get lost with the comma as it is used as header separator.
2. Cookies with values "0" are parsed as undef
3. Google sends cookies with embedded '=', which are wrongly parsed (is
this valid?)
4. As have been said, issues with flags like 'HTTPonly' and friends
In the attached script (near line 70) I made some comments and changes
to deal with these issues.
The idea is something like follows, what do you think?
--- HTTP.pm
+++ HTTP.mine.pm
@@ -595,16 +595,17 @@
# set-cookie processing
if ($arg{cookie_jar}) {
+ $_[1]{"set-cookie"} =~
s/(expires\s*=\s*)([^";]*GMT)/$1"$2"/gi; #TODO: review
for ($_[1]{"set-cookie"}) {
# parse NAME=VALUE
my @kv;
- while (/\G\s* ([^=;,[:space:]]+) \s*=\s* (?:
"((?:[^\\"]+|\\.)*)" | ([^=;,[:space:]]*) )/gcxs) {
+ while (/\G\s* ([^=;,[:space:]]+) (?: \s*=\s*
(?: "((?:[^\\"]+|\\.)*)" | ([^;,[:space:]]*) ))?/gcxs) {
my $name = $1;
my $value = $3;
- unless ($value) {
- $value = $2;
+ unless (defined $value) {
+ $value = (defined $2) ? $2 : 1;
$value =~ s/\\(.)/$1/gs;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ae_cookies.pl
Type: application/x-perl
Size: 5553 bytes
Desc: not available
URL: <http://lists.schmorp.de/pipermail/anyevent/attachments/20100620/ca1b4e77/attachment-0001.bin>
More information about the anyevent
mailing list