Skip to content

Commit

Permalink
Merge pull request #198 from peelle/master
Browse files Browse the repository at this point in the history
Added support for HTTP/2 Cookie Headers
  • Loading branch information
patrickbkr authored Aug 3, 2024
2 parents 4a42e25 + c1d6c52 commit ee938bb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/Cro/HTTP/Request.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -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('=');
Expand Down
8 changes: 8 additions & 0 deletions t/http-request.t
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

{
Expand Down

0 comments on commit ee938bb

Please sign in to comment.