| 1 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | =encoding utf8 | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | =head1 NAME | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | Quiq::Http::Cookie - HTTP-Cookie | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | =head1 BASE CLASS | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | L<Quiq::Hash> | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | Ein Objekt der Klasse repräsentiert einen HTTP-Cookie gemäß der klassischen | ||||||||||||||||||||||||||||
| 16 | L<Netscape-Spezifikation|http://de.wikipedia.org/wiki/HTTP-Cookie#Cookie_nach_Netscape>. Die Klasse wird typischerweise verwendet, | ||||||||||||||||||||||||||||
| 17 | um Set-Cookie Header zu generieren. | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | =head1 CAVEATS | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | Der Name und der Wert des Cookie werden aktuell nicht kodiert. | ||||||||||||||||||||||||||||
| 22 | Name und Wert sollten daher nur aus druckbaren ASCII-Zeichen | ||||||||||||||||||||||||||||
| 23 | ohne Semikolon, Komma, Gleichheitszeichen und Leerzeichen bestehen. | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | =over 4 | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | =item name => $name | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | Der Name des Cookie. | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | =item value => $value | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | Der Wert des Cookie. | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | =item domain => $domain (optional) | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | Die Domain, an die der Browser den Cookie schickt. Fehlt die Angabe, | ||||||||||||||||||||||||||||
| 40 | nimmt der Browser den Hostnamen des URL an. | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | =item path => $path (optional) | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | Der Pfad, an den der Browser den Cookie schickt. Fehlt die Angabe, | ||||||||||||||||||||||||||||
| 45 | nimmt der Browser den Pfad des URL an. | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | =item expires => $time (optional) | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | Verfallszeitpunkt des Cookie nach RFC822 im Format | ||||||||||||||||||||||||||||
| 50 | "Wdy, DD Mon YYYY HH:MM:SS GMT" oder mit einer Zeitangabe nach | ||||||||||||||||||||||||||||
| 51 | Quiq::Time::RFC822 (siehe Abschnitt L<EXAMPLES|"EXAMPLES">). Fehlt die Angabe, | ||||||||||||||||||||||||||||
| 52 | verfällt der Cookie mit dem Schließen des Browsers. | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | =item secure => $bool (optional) | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | Wenn wahr, wird der Cookie vom Browser nur über eine sichere | ||||||||||||||||||||||||||||
| 57 | HTTPS-Verbindung geschickt. | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | =back | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | =over 2 | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | =item * | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | Cookie-Spezifikation von Netscape | ||||||||||||||||||||||||||||
| 68 | (L<http://de.wikipedia.org/wiki/HTTP-Cookie#Cookie_nach_Netscape>) | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | =back | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | =head1 EXAMPLES | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | =head2 Cookie für eine Browser-Sitzung | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | my $cok = Quiq::Http::Cookie->new(sid=>4711); | ||||||||||||||||||||||||||||
| 77 | print 'Set-Cookie: ',$cok->asString; | ||||||||||||||||||||||||||||
| 78 | __END__ | ||||||||||||||||||||||||||||
| 79 | Set-Cookie: sid=4711 | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | =head2 Cookie verfällt in einem Jahr (Aufruf am 2011-11-11 12:24:12 GMT) | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | my $cok = Quiq::Http::Cookie->new(sid=>4711,expires=>'+1y'); | ||||||||||||||||||||||||||||
| 84 | print 'Set-Cookie: ',$cok->asString; | ||||||||||||||||||||||||||||
| 85 | __END__ | ||||||||||||||||||||||||||||
| 86 | Set-Cookie: sid=4711; expires=Fri, 11-Nov-2012 12:24:12 GMT | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | Die Angabe '+1y' wird von Methode L<asString|"asString() - Generiere Zeichenketten-Repräsentation">() durch Aufruf | ||||||||||||||||||||||||||||
| 89 | von Quiq::Time::RFC822->get() in eine gültige RFC822-Datumsangabe | ||||||||||||||||||||||||||||
| 90 | gewandelt. Weitere abkürzende Schreibweisen siehe dort. | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | =cut | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | package Quiq::Http::Cookie; | ||||||||||||||||||||||||||||
| 97 | 3 | ▶ | use base qw/Quiq::Hash/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 3 | ▶ | use v5.10; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 100 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 101 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 3 | our $VERSION = '1.240'; | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 3 | ▶ | use Quiq::Time::RFC822; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | =head1 METHODS | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | =head2 Konstruktor | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | =head3 new() - Konstruktor | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | =head4 Synopsis | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | $cok = $class->new($name=>$value,@keyVal); | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | =head4 Returns | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | Referenz auf das Cookie-Objekt. | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | =head4 Description | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | Instantiiere einen Cookie mit Name $name, Wert $value und den | ||||||||||||||||||||||||||||
| 126 | optionalen Attributen @keyVal. | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | Siehe Abschnitt L<ATTRIBUTES|"ATTRIBUTES"> für mögliche Werte für @keyVal. | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | =cut | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 2 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 135 | 2 | my $class = shift; | |||||||||||||||||||||||||||
| 136 | 2 | my $name = shift; | |||||||||||||||||||||||||||
| 137 | 2 | my $value = shift; | |||||||||||||||||||||||||||
| 138 | # @_: @options | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 2 | my $self = $class->SUPER::new( | |||||||||||||||||||||||||||
| 141 | name => $name, | ||||||||||||||||||||||||||||
| 142 | value => $value, | ||||||||||||||||||||||||||||
| 143 | domain => undef, | ||||||||||||||||||||||||||||
| 144 | path => undef, | ||||||||||||||||||||||||||||
| 145 | expires => undef, | ||||||||||||||||||||||||||||
| 146 | secure => 0, | ||||||||||||||||||||||||||||
| 147 | ); | ||||||||||||||||||||||||||||
| 148 | 2 | $self->set(@_); | |||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 2 | return $self; | |||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | =head2 Objektmethoden | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | =head3 asString() - Generiere Zeichenketten-Repräsentation | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | =head4 Synopsis | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | $str = $cok->asString; | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | =head4 Returns | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | Zeichnketten-Repräsentation des Cookie. | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | =head4 Description | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | Generiere eine Zeichenketten-Repräsentation des Cookie, die als | ||||||||||||||||||||||||||||
| 170 | Wert für einen Set-Cookie Header eingesetzt werden kann. | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | =cut | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | 1 | ▶ | sub asString { | ||||||||||||||||||||||||||
|
Subroutine
asString: called CC=7 SCAR=22.5
Pod
documented
| |||||||||||||||||||||||||||||
| 177 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 1 | my ($name,$value,$domain,$path,$expires,$secure) = | |||||||||||||||||||||||||||
| 180 | $self->get(qw/name value domain path expires secure/); | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 1 | my $str = "$name=$value"; | |||||||||||||||||||||||||||
| 183 | 1 | ▶ | if ($domain) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 184 | 0 | $str .= "; domain=$domain"; | |||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||
| 186 | 1 | ▶ | if ($path) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 187 | 0 | $str .= "; path=$path"; | |||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | 1 | ▶ | if (defined $expires) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 190 | 1 | ▶ | if ($expires eq '0' || $expires eq 'now') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$expires eq 0 or $expires eq "now"
MC/DC0%0/2
$expires eq 0 or $expires eq "now"
$expires eq 0
$expires eq "now"
Truth table33%1/3
A or B
A= $expires eq 0B= $expires eq "now"
| |||||||||||||||||||||||||||||
| 191 | # 0 ist ungeeignet, da Netscape Cookies | ||||||||||||||||||||||||||||
| 192 | # mit diesem Datum ignoriert | ||||||||||||||||||||||||||||
| 193 | 1 | $expires = 1; | |||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | 1 | $str .= sprintf "; expires=%s",Quiq::Time::RFC822->get($expires); | |||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||
| 197 | 1 | ▶ | if ($secure) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 198 | 0 | $str .= '; secure'; | |||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | 1 | return $str; | |||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | =head1 VERSION | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | 1.240 | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | Frank Seitz, L<http://fseitz.de/> | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | Copyright (C) 2026 Frank Seitz | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | =head1 LICENSE | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | This code is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 221 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | =cut | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | 3 | 1; | |||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | # eof | ||||||||||||||||||||||||||||