-
-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathCookie.rakumod
73 lines (48 loc) · 1.44 KB
/
Cookie.rakumod
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
unit class HTTP::Cookie;
has $.name is rw;
has $.value is rw;
has $.secure is rw;
has $.httponly is rw;
has $.path is rw;
has $.domain is rw;
has $.version is rw;
has $.expires is rw;
has %.fields;
method Str {
my $s = "$.name=$.value";
$s ~= "; Domain=$.domain" if $.domain;
$s ~= "; Version=$.version" if $.version;
$s ~= "; Path=$.path" if $.path;
$s ~= "; Expires=$.expires" if $.expires;
$s ~= ';' ~ (%.fields.map( *.fmt("%s=%s") )).flat.join('; ') if %.fields.elems > 1;
$s ~= "; $.secure" if $.secure;
$s ~= "; $.httponly" if $.httponly;
$s;
}
=begin pod
=head1 NAME
HTTP::Cookie - HTTP cookie class
=head1 SYNOPSIS
use HTTP::Cookie;
my $cookie = HTTP::Cookie.new(:name<test_name>, :value<test_value>);
say ~$cookie;
=head1 DESCRIPTION
This module encapsulates single HTTP Cookie.
=head1 METHODS
The following methods are provided:
=head2 method new
method new(HTTP::Cookie:, *%params)
A constructor, it takes hash parameters, like:
name: name of a cookie
value: value of a cookie
secure: Secure param
httponly: HttpOnly param
fields: hash of fields (field => value)
Example:
my $c = HTTP::Cookie.new(:name<a_cookie>, :value<a_value>, :secure, fields => (a => b));
=head2 method Str
method Str(HTTP::Cookie:)
Returns a cookie (as a String) in readable (RFC2109) form.
=head1 SEE ALSO
L<HTTP::Cookies>, L<HTTP::Request>, L<HTTP::Response>
=end pod