From fc1fc107e48f4c120542f3d55dadb7a5c5e24ce3 Mon Sep 17 00:00:00 2001 From: Jeremy Carman Date: Fri, 2 Aug 2024 17:42:21 +0800 Subject: [PATCH 1/2] Added support for HTTP/2 cookie headers. --- lib/Cro/HTTP/Request.pm6 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/Cro/HTTP/Request.pm6 b/lib/Cro/HTTP/Request.pm6 index eb5e721a..2de940c4 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('='); From c1d6c529d9a201e978ef1d1b414e468f87e27636 Mon Sep 17 00:00:00 2001 From: Jeremy Carman Date: Fri, 2 Aug 2024 17:42:48 +0800 Subject: [PATCH 2/2] Added tests for Cookie behavior. --- t/http-request.t | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/t/http-request.t b/t/http-request.t index 0736dfbb..c55acb5f 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'; } {