diff --git a/lib/AnyEvent/HTTP/Server.pm b/lib/AnyEvent/HTTP/Server.pm index be8cc8c..5adc159 100644 --- a/lib/AnyEvent/HTTP/Server.pm +++ b/lib/AnyEvent/HTTP/Server.pm @@ -378,13 +378,14 @@ sub incoming { $lastkey = lc $1; $h{ $lastkey } = exists $h{ $lastkey } ? $h{ $lastkey }.','.$2: $2; #warn "Captured header $lastkey = '$2'"; + my $v = $2; if ( defined $3 ) { - pos(my $v = $2) = $-[3] - $-[2]; - #warn "scan ';'"; $h{ $lastkey . '+' . lc($1) } = ( defined $2 ? do { my $x = $2; $x =~ s{\\(.)}{$1}gs; $x } : $3 ) - while ( $v =~ m{ \G ; \s* ([^\s=]++)\s*= (?: "((?:[^\\"]++|\\.){0,4096}+)" | ([^;,\s]++) ) \s* }gcxso ); # " + while ( $v =~ m{ \s* ([^\s=]++)\s*= (?: "((?:[^\\"]++|\\.){0,4096}+)" | ([^;,\s]++) ) \s* ;? }gcxso ); # " $contstate = 1; - } else { + } else { + $h{ $lastkey . '+' . lc($1) } = ( defined $2 ? do { my $x = $2; $x =~ s{\\(.)}{$1}gs; $x } : $3 ) + if ( $v =~ m{ \s* ([^\s=]++)\s*= (?: "((?:[^\\"]++|\\.){0,4096}+)" | ([^;,\s]++) ) \s* ;? }xso ); # " $contstate = 0; } } diff --git a/t/basic.pl b/t/basic.pl index 487a35b..b37ee39 100644 --- a/t/basic.pl +++ b/t/basic.pl @@ -1,6 +1,6 @@ #!/usr/bin/env perl -use Test::More tests => 224; +use Test::More tests => 244; use Data::Dumper; use FindBin; use lib "$FindBin::Bin/.."; @@ -291,6 +291,23 @@ [["GET /test1 HTTP/1.1\nHost:localhost\nConnection:keep-alive\n\n"], 200, { 'content-length' => 0 }, "" ], if ALL; +test_server { + my $s = shift; + my $r = shift; + return ( + $r->method eq 'GET' ? 200 : 400, + "x=".$r->headers->{'cookie+x'}.",y=".$r->headers->{'cookie+y'}, + headers => { + }, + ); +} 'Cookies parsing', + [["GET /test1 HTTP/1.1\nCookie: x=1\n\n"], 200, { }, "x=1,y=" ], + [["GET /test2 HTTP/1.1\nCookie: x=1;y=2\n\n"], 200, { }, "x=1,y=2" ], + [["GET /test2 HTTP/1.1\nCookie: x=\"1\";y=2\n\n"], 200, { }, "x=1,y=2" ], + [["GET /test2 HTTP/1.1\nCookie: x=1;y=\"2\"\n\n"], 200, { }, "x=1,y=2" ], + [["GET /test2 HTTP/1.1\nCookie: x=\"1\";y=\"2\"\n\n"], 200, { }, "x=1,y=2" ], +if ALL; + } done_testing();