diff --git a/lib/Cro/HTTP/Request.pm6 b/lib/Cro/HTTP/Request.pm6 index eb5e721..2de940c 100644 --- a/lib/Cro/HTTP/Request.pm6 +++ b/lib/Cro/HTTP/Request.pm6 @@ -162,7 +162,9 @@ class Cro::HTTP::Request does Cro::HTTP::Message { method !unpack-cookie(--> List) { my @str = self.headers.grep({ .name.lc eq 'cookie' }); return () if @str.elems == 0; - @str = @str[0].value.split(/';' ' '?/).List; + @str = self.http-version.defined && self.http-version eq '2.0' + ?? @str.map({ .value.split(/';' ' '?/).List })[*;*] + !! @str[0].value.split(/';' ' '?/).List; my @res; for @str { my ($name, $value) = $_.split('='); diff --git a/t/http-request.t b/t/http-request.t index 0736dfb..c55acb5 100644 --- a/t/http-request.t +++ b/t/http-request.t @@ -200,6 +200,14 @@ use Test; dies-ok { $req.add-cookie('', '') }, 'Empty names are not permitted'; $req.add-cookie('Heaven', 'Valhalla'); like $req.Str, /"GET / HTTP/1.0\r\nCookie: " ['Foo=Bar' || 'Heaven=Valhalla' || 'Lang=US'] ** 3 % '; ' "\r\n\r\n"/, 'Cookie header looks good'; + + # Default behavior for HTTP 1.1 + $req.remove-cookie('lang'); + $req.append-header(Cro::HTTP::Header.new(name => 'cookie', value => 'lang=us')); + is $req.has-cookie('lang'), False, 'lang cookie header should not be parsed for HTTP 1.1'; + + $req.http-version = '2.0'; + is $req.has-cookie('lang'), True, 'lang cookie header should be parsed for HTTP 2'; } {