Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for HTTP/2 Cookie Headers #198

Merged
merged 2 commits into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading