line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTTP::Headers; |
2
|
|
|
|
|
|
|
|
3
|
17
|
|
|
17
|
|
287222
|
use strict; |
|
17
|
|
|
|
|
77
|
|
|
17
|
|
|
|
|
518
|
|
4
|
17
|
|
|
17
|
|
91
|
use warnings; |
|
17
|
|
|
|
|
32
|
|
|
17
|
|
|
|
|
657
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '6.43'; |
7
|
|
|
|
|
|
|
|
8
|
17
|
|
|
17
|
|
98
|
use Carp (); |
|
17
|
|
|
|
|
31
|
|
|
17
|
|
|
|
|
62162
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# The $TRANSLATE_UNDERSCORE variable controls whether '_' can be used |
11
|
|
|
|
|
|
|
# as a replacement for '-' in header field names. |
12
|
|
|
|
|
|
|
our $TRANSLATE_UNDERSCORE = 1 unless defined $TRANSLATE_UNDERSCORE; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# "Good Practice" order of HTTP message headers: |
15
|
|
|
|
|
|
|
# - General-Headers |
16
|
|
|
|
|
|
|
# - Request-Headers |
17
|
|
|
|
|
|
|
# - Response-Headers |
18
|
|
|
|
|
|
|
# - Entity-Headers |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my @general_headers = qw( |
21
|
|
|
|
|
|
|
Cache-Control Connection Date Pragma Trailer Transfer-Encoding Upgrade |
22
|
|
|
|
|
|
|
Via Warning |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my @request_headers = qw( |
26
|
|
|
|
|
|
|
Accept Accept-Charset Accept-Encoding Accept-Language |
27
|
|
|
|
|
|
|
Authorization Expect From Host |
28
|
|
|
|
|
|
|
If-Match If-Modified-Since If-None-Match If-Range If-Unmodified-Since |
29
|
|
|
|
|
|
|
Max-Forwards Proxy-Authorization Range Referer TE User-Agent |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my @response_headers = qw( |
33
|
|
|
|
|
|
|
Accept-Ranges Age ETag Location Proxy-Authenticate Retry-After Server |
34
|
|
|
|
|
|
|
Vary WWW-Authenticate |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my @entity_headers = qw( |
38
|
|
|
|
|
|
|
Allow Content-Encoding Content-Language Content-Length Content-Location |
39
|
|
|
|
|
|
|
Content-MD5 Content-Range Content-Type Expires Last-Modified |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my %entity_header = map { lc($_) => 1 } @entity_headers; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
my @header_order = ( |
45
|
|
|
|
|
|
|
@general_headers, |
46
|
|
|
|
|
|
|
@request_headers, |
47
|
|
|
|
|
|
|
@response_headers, |
48
|
|
|
|
|
|
|
@entity_headers, |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# Make alternative representations of @header_order. This is used |
52
|
|
|
|
|
|
|
# for sorting and case matching. |
53
|
|
|
|
|
|
|
my %header_order; |
54
|
|
|
|
|
|
|
my %standard_case; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
{ |
57
|
|
|
|
|
|
|
my $i = 0; |
58
|
|
|
|
|
|
|
for (@header_order) { |
59
|
|
|
|
|
|
|
my $lc = lc $_; |
60
|
|
|
|
|
|
|
$header_order{$lc} = ++$i; |
61
|
|
|
|
|
|
|
$standard_case{$lc} = $_; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub new |
68
|
|
|
|
|
|
|
{ |
69
|
203
|
|
|
203
|
1
|
1955855
|
my($class) = shift; |
70
|
203
|
|
|
|
|
459
|
my $self = bless {}, $class; |
71
|
203
|
100
|
|
|
|
704
|
$self->header(@_) if @_; # set up initial headers |
72
|
203
|
|
|
|
|
567
|
$self; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub header |
77
|
|
|
|
|
|
|
{ |
78
|
512
|
|
|
512
|
1
|
7299
|
my $self = shift; |
79
|
512
|
100
|
|
|
|
1253
|
Carp::croak('Usage: $h->header($field, ...)') unless @_; |
80
|
511
|
|
|
|
|
788
|
my(@old); |
81
|
|
|
|
|
|
|
my %seen; |
82
|
511
|
|
|
|
|
1057
|
while (@_) { |
83
|
570
|
|
|
|
|
894
|
my $field = shift; |
84
|
570
|
100
|
|
|
|
1565
|
my $op = @_ ? ($seen{lc($field)}++ ? 'PUSH' : 'SET') : 'GET'; |
|
|
100
|
|
|
|
|
|
85
|
570
|
|
|
|
|
1274
|
@old = $self->_header($field, shift, $op); |
86
|
|
|
|
|
|
|
} |
87
|
509
|
100
|
|
|
|
1255
|
return @old if wantarray; |
88
|
449
|
100
|
|
|
|
2051
|
return $old[0] if @old <= 1; |
89
|
6
|
|
|
|
|
35
|
join(", ", @old); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub clear |
93
|
|
|
|
|
|
|
{ |
94
|
9
|
|
|
9
|
1
|
1590
|
my $self = shift; |
95
|
9
|
|
|
|
|
37
|
%$self = (); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub push_header |
100
|
|
|
|
|
|
|
{ |
101
|
133
|
|
|
133
|
1
|
1251
|
my $self = shift; |
102
|
133
|
100
|
|
|
|
378
|
return $self->_header(@_, 'PUSH_H') if @_ == 2; |
103
|
1
|
|
|
|
|
5
|
while (@_) { |
104
|
2
|
|
|
|
|
7
|
$self->_header(splice(@_, 0, 2), 'PUSH_H'); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub init_header |
110
|
|
|
|
|
|
|
{ |
111
|
5
|
100
|
|
5
|
1
|
93
|
Carp::croak('Usage: $h->init_header($field, $val)') if @_ != 3; |
112
|
4
|
|
|
|
|
11
|
shift->_header(@_, 'INIT'); |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub remove_header |
117
|
|
|
|
|
|
|
{ |
118
|
48
|
|
|
48
|
1
|
1165
|
my($self, @fields) = @_; |
119
|
48
|
|
|
|
|
84
|
my $field; |
120
|
|
|
|
|
|
|
my @values; |
121
|
48
|
|
|
|
|
90
|
foreach $field (@fields) { |
122
|
84
|
100
|
100
|
|
|
349
|
$field =~ tr/_/-/ if $field !~ /^:/ && $TRANSLATE_UNDERSCORE; |
123
|
84
|
|
|
|
|
205
|
my $v = delete $self->{lc $field}; |
124
|
84
|
100
|
|
|
|
264
|
push(@values, ref($v) eq 'ARRAY' ? @$v : $v) if defined $v; |
|
|
100
|
|
|
|
|
|
125
|
|
|
|
|
|
|
} |
126
|
48
|
|
|
|
|
169
|
return @values; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub remove_content_headers |
130
|
|
|
|
|
|
|
{ |
131
|
9
|
|
|
9
|
1
|
30
|
my $self = shift; |
132
|
9
|
100
|
|
|
|
52
|
unless (defined(wantarray)) { |
133
|
|
|
|
|
|
|
# fast branch that does not create return object |
134
|
5
|
|
100
|
|
|
48
|
delete @$self{grep $entity_header{$_} || /^content-/, keys %$self}; |
135
|
5
|
|
|
|
|
19
|
return; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
4
|
|
|
|
|
16
|
my $c = ref($self)->new; |
139
|
4
|
|
100
|
|
|
93
|
for my $f (grep $entity_header{$_} || /^content-/, keys %$self) { |
140
|
11
|
|
|
|
|
36
|
$c->{$f} = delete $self->{$f}; |
141
|
|
|
|
|
|
|
} |
142
|
4
|
100
|
|
|
|
15
|
if (exists $self->{'::std_case'}) { |
143
|
2
|
|
|
|
|
5
|
$c->{'::std_case'} = $self->{'::std_case'}; |
144
|
|
|
|
|
|
|
} |
145
|
4
|
|
|
|
|
15
|
$c; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub _header |
150
|
|
|
|
|
|
|
{ |
151
|
960
|
|
|
960
|
|
2291
|
my($self, $field, $val, $op) = @_; |
152
|
|
|
|
|
|
|
|
153
|
960
|
100
|
100
|
|
|
4135
|
Carp::croak("Illegal field name '$field'") |
154
|
|
|
|
|
|
|
if rindex($field, ':') > 1 || !length($field); |
155
|
|
|
|
|
|
|
|
156
|
958
|
100
|
|
|
|
2407
|
unless ($field =~ /^:/) { |
157
|
946
|
100
|
|
|
|
2123
|
$field =~ tr/_/-/ if $TRANSLATE_UNDERSCORE; |
158
|
946
|
|
|
|
|
1559
|
my $old = $field; |
159
|
946
|
|
|
|
|
1529
|
$field = lc $field; |
160
|
946
|
100
|
100
|
|
|
2696
|
unless($standard_case{$field} || $self->{'::std_case'}{$field}) { |
161
|
|
|
|
|
|
|
# generate a %std_case entry for this field |
162
|
124
|
|
|
|
|
938
|
$old =~ s/\b(\w)/\u$1/g; |
163
|
124
|
|
|
|
|
417
|
$self->{'::std_case'}{$field} = $old; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
958
|
100
|
66
|
|
|
2318
|
$op ||= defined($val) ? 'SET' : 'GET'; |
168
|
958
|
100
|
|
|
|
1930
|
if ($op eq 'PUSH_H') { |
169
|
|
|
|
|
|
|
# Like PUSH but where we don't care about the return value |
170
|
134
|
100
|
|
|
|
290
|
if (exists $self->{$field}) { |
171
|
23
|
|
|
|
|
40
|
my $h = $self->{$field}; |
172
|
23
|
100
|
|
|
|
54
|
if (ref($h) eq 'ARRAY') { |
173
|
3
|
100
|
|
|
|
12
|
push(@$h, ref($val) eq "ARRAY" ? @$val : $val); |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
else { |
176
|
20
|
100
|
|
|
|
66
|
$self->{$field} = [$h, ref($val) eq "ARRAY" ? @$val : $val] |
177
|
|
|
|
|
|
|
} |
178
|
23
|
|
|
|
|
66
|
return; |
179
|
|
|
|
|
|
|
} |
180
|
111
|
|
|
|
|
211
|
$self->{$field} = $val; |
181
|
111
|
|
|
|
|
315
|
return; |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
824
|
|
|
|
|
1413
|
my $h = $self->{$field}; |
185
|
824
|
100
|
|
|
|
2161
|
my @old = ref($h) eq 'ARRAY' ? @$h : (defined($h) ? ($h) : ()); |
|
|
100
|
|
|
|
|
|
186
|
|
|
|
|
|
|
|
187
|
824
|
100
|
100
|
|
|
2051
|
unless ($op eq 'GET' || ($op eq 'INIT' && @old)) { |
|
|
|
100
|
|
|
|
|
188
|
281
|
100
|
|
|
|
499
|
if (defined($val)) { |
|
|
50
|
|
|
|
|
|
189
|
280
|
100
|
|
|
|
545
|
my @new = ($op eq 'PUSH') ? @old : (); |
190
|
280
|
100
|
|
|
|
510
|
if (ref($val) ne 'ARRAY') { |
191
|
272
|
|
|
|
|
492
|
push(@new, $val); |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
else { |
194
|
8
|
|
|
|
|
16
|
push(@new, @$val); |
195
|
|
|
|
|
|
|
} |
196
|
280
|
100
|
|
|
|
784
|
$self->{$field} = @new > 1 ? \@new : $new[0]; |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
elsif ($op ne 'PUSH') { |
199
|
1
|
|
|
|
|
2
|
delete $self->{$field}; |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
} |
202
|
824
|
|
|
|
|
2502
|
@old; |
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
sub _sorted_field_names |
207
|
|
|
|
|
|
|
{ |
208
|
175
|
|
|
175
|
|
268
|
my $self = shift; |
209
|
|
|
|
|
|
|
return [ sort { |
210
|
175
|
50
|
100
|
|
|
1973
|
($header_order{$a} || 999) <=> ($header_order{$b} || 999) || |
|
349
|
|
100
|
|
|
1712
|
|
211
|
|
|
|
|
|
|
$a cmp $b |
212
|
|
|
|
|
|
|
} grep !/^::/, keys %$self ]; |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
sub header_field_names { |
217
|
15
|
|
|
15
|
1
|
1556
|
my $self = shift; |
218
|
15
|
100
|
66
|
|
|
43
|
return map $standard_case{$_} || $self->{'::std_case'}{$_} || $_, @{ $self->_sorted_field_names }, |
|
10
|
|
|
|
|
22
|
|
219
|
|
|
|
|
|
|
if wantarray; |
220
|
5
|
|
|
|
|
38
|
return grep !/^::/, keys %$self; |
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
sub scan |
225
|
|
|
|
|
|
|
{ |
226
|
39
|
|
|
39
|
1
|
2496
|
my($self, $sub) = @_; |
227
|
39
|
|
|
|
|
79
|
my $key; |
228
|
39
|
|
|
|
|
69
|
for $key (@{ $self->_sorted_field_names }) { |
|
39
|
|
|
|
|
102
|
|
229
|
93
|
|
|
|
|
206
|
my $vals = $self->{$key}; |
230
|
93
|
100
|
|
|
|
237
|
if (ref($vals) eq 'ARRAY') { |
231
|
15
|
|
|
|
|
15
|
my $val; |
232
|
15
|
|
|
|
|
29
|
for $val (@$vals) { |
233
|
33
|
|
66
|
|
|
131
|
$sub->($standard_case{$key} || $self->{'::std_case'}{$key} || $key, $val); |
234
|
|
|
|
|
|
|
} |
235
|
|
|
|
|
|
|
} |
236
|
|
|
|
|
|
|
else { |
237
|
78
|
|
66
|
|
|
267
|
$sub->($standard_case{$key} || $self->{'::std_case'}{$key} || $key, $vals); |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
} |
240
|
|
|
|
|
|
|
} |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
sub flatten { |
243
|
2
|
|
|
2
|
1
|
8
|
my($self)=@_; |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
( |
246
|
|
|
|
|
|
|
map { |
247
|
2
|
|
|
|
|
5
|
my $k = $_; |
|
6
|
|
|
|
|
11
|
|
248
|
|
|
|
|
|
|
map { |
249
|
6
|
|
|
|
|
11
|
( $k => $_ ) |
|
8
|
|
|
|
|
37
|
|
250
|
|
|
|
|
|
|
} $self->header($_); |
251
|
|
|
|
|
|
|
} $self->header_field_names |
252
|
|
|
|
|
|
|
); |
253
|
|
|
|
|
|
|
} |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
sub as_string |
256
|
|
|
|
|
|
|
{ |
257
|
126
|
|
|
126
|
1
|
2701
|
my($self, $endl) = @_; |
258
|
126
|
100
|
|
|
|
280
|
$endl = "\n" unless defined $endl; |
259
|
|
|
|
|
|
|
|
260
|
126
|
|
|
|
|
211
|
my @result = (); |
261
|
126
|
|
|
|
|
170
|
for my $key (@{ $self->_sorted_field_names }) { |
|
126
|
|
|
|
|
283
|
|
262
|
219
|
50
|
|
|
|
558
|
next if index($key, '_') == 0; |
263
|
219
|
|
|
|
|
363
|
my $vals = $self->{$key}; |
264
|
219
|
100
|
|
|
|
407
|
if ( ref($vals) eq 'ARRAY' ) { |
265
|
14
|
|
|
|
|
35
|
for my $val (@$vals) { |
266
|
35
|
50
|
|
|
|
82
|
$val = '' if not defined $val; |
267
|
35
|
|
66
|
|
|
110
|
my $field = $standard_case{$key} || $self->{'::std_case'}{$key} || $key; |
268
|
35
|
|
|
|
|
67
|
$field =~ s/^://; |
269
|
35
|
50
|
|
|
|
127
|
if ( index($val, "\n") >= 0 ) { |
270
|
0
|
|
|
|
|
0
|
$val = _process_newline($val, $endl); |
271
|
|
|
|
|
|
|
} |
272
|
35
|
|
|
|
|
93
|
push @result, $field . ': ' . $val; |
273
|
|
|
|
|
|
|
} |
274
|
|
|
|
|
|
|
} |
275
|
|
|
|
|
|
|
else { |
276
|
205
|
50
|
|
|
|
434
|
$vals = '' if not defined $vals; |
277
|
205
|
|
66
|
|
|
592
|
my $field = $standard_case{$key} || $self->{'::std_case'}{$key} || $key; |
278
|
205
|
|
|
|
|
323
|
$field =~ s/^://; |
279
|
205
|
100
|
|
|
|
452
|
if ( index($vals, "\n") >= 0 ) { |
280
|
13
|
|
|
|
|
33
|
$vals = _process_newline($vals, $endl); |
281
|
|
|
|
|
|
|
} |
282
|
205
|
|
|
|
|
578
|
push @result, $field . ': ' . $vals; |
283
|
|
|
|
|
|
|
} |
284
|
|
|
|
|
|
|
} |
285
|
|
|
|
|
|
|
|
286
|
126
|
|
|
|
|
1317
|
join($endl, @result, ''); |
287
|
|
|
|
|
|
|
} |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
sub _process_newline { |
290
|
13
|
|
|
13
|
|
25
|
local $_ = shift; |
291
|
13
|
|
|
|
|
22
|
my $endl = shift; |
292
|
|
|
|
|
|
|
# must handle header values with embedded newlines with care |
293
|
13
|
|
|
|
|
45
|
s/\s+$//; # trailing newlines and space must go |
294
|
13
|
|
|
|
|
41
|
s/\n(\x0d?\n)+/\n/g; # no empty lines |
295
|
13
|
|
|
|
|
49
|
s/\n([^\040\t])/\n $1/g; # initial space for continuation |
296
|
13
|
|
|
|
|
39
|
s/\n/$endl/g; # substitute with requested line ending |
297
|
13
|
|
|
|
|
31
|
$_; |
298
|
|
|
|
|
|
|
} |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
if (eval { require Clone; 1 }) { |
303
|
|
|
|
|
|
|
*clone = \&Clone::clone; |
304
|
|
|
|
|
|
|
} else { |
305
|
|
|
|
|
|
|
*clone = sub { |
306
|
34
|
|
|
34
|
|
3012
|
my $self = shift; |
307
|
34
|
|
|
|
|
98
|
my $clone = HTTP::Headers->new; |
308
|
34
|
|
|
91
|
|
246
|
$self->scan(sub { $clone->push_header(@_);} ); |
|
91
|
|
|
|
|
217
|
|
309
|
34
|
|
|
|
|
209
|
$clone; |
310
|
|
|
|
|
|
|
}; |
311
|
|
|
|
|
|
|
} |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
sub _date_header |
315
|
|
|
|
|
|
|
{ |
316
|
134
|
|
|
134
|
|
1742
|
require HTTP::Date; |
317
|
134
|
|
|
|
|
9369
|
my($self, $header, $time) = @_; |
318
|
134
|
|
|
|
|
276
|
my($old) = $self->_header($header); |
319
|
134
|
100
|
|
|
|
294
|
if (defined $time) { |
320
|
17
|
|
|
|
|
51
|
$self->_header($header, HTTP::Date::time2str($time)); |
321
|
|
|
|
|
|
|
} |
322
|
134
|
100
|
|
|
|
296
|
$old =~ s/;.*// if defined($old); |
323
|
134
|
|
|
|
|
292
|
HTTP::Date::str2time($old); |
324
|
|
|
|
|
|
|
} |
325
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
|
327
|
50
|
|
|
50
|
1
|
575
|
sub date { shift->_date_header('Date', @_); } |
328
|
25
|
|
|
25
|
1
|
1303
|
sub expires { shift->_date_header('Expires', @_); } |
329
|
5
|
|
|
5
|
1
|
1459
|
sub if_modified_since { shift->_date_header('If-Modified-Since', @_); } |
330
|
3
|
|
|
3
|
1
|
1453
|
sub if_unmodified_since { shift->_date_header('If-Unmodified-Since', @_); } |
331
|
22
|
|
|
22
|
1
|
1488
|
sub last_modified { shift->_date_header('Last-Modified', @_); } |
332
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
# This is used as a private LWP extension. The Client-Date header is |
334
|
|
|
|
|
|
|
# added as a timestamp to a response when it has been received. |
335
|
28
|
|
|
28
|
0
|
57
|
sub client_date { shift->_date_header('Client-Date', @_); } |
336
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
# The retry_after field is dual format (can also be a expressed as |
338
|
|
|
|
|
|
|
# number of seconds from now), so we don't provide an easy way to |
339
|
|
|
|
|
|
|
# access it until we have know how both these interfaces can be |
340
|
|
|
|
|
|
|
# addressed. One possibility is to return a negative value for |
341
|
|
|
|
|
|
|
# relative seconds and a positive value for epoch based time values. |
342
|
|
|
|
|
|
|
#sub retry_after { shift->_date_header('Retry-After', @_); } |
343
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
sub content_type { |
345
|
422
|
|
|
422
|
1
|
1107
|
my $self = shift; |
346
|
422
|
|
|
|
|
637
|
my $ct = $self->{'content-type'}; |
347
|
422
|
100
|
|
|
|
969
|
$self->{'content-type'} = shift if @_; |
348
|
422
|
50
|
|
|
|
861
|
$ct = $ct->[0] if ref($ct) eq 'ARRAY'; |
349
|
422
|
100
|
100
|
|
|
1494
|
return '' unless defined($ct) && length($ct); |
350
|
381
|
|
|
|
|
1194
|
my @ct = split(/;\s*/, $ct, 2); |
351
|
381
|
|
|
|
|
744
|
for ($ct[0]) { |
352
|
381
|
|
|
|
|
756
|
s/\s+//g; |
353
|
381
|
|
|
|
|
792
|
$_ = lc($_); |
354
|
|
|
|
|
|
|
} |
355
|
381
|
100
|
|
|
|
1994
|
wantarray ? @ct : $ct[0]; |
356
|
|
|
|
|
|
|
} |
357
|
|
|
|
|
|
|
|
358
|
|
|
|
|
|
|
sub content_type_charset { |
359
|
92
|
|
|
92
|
1
|
141
|
my $self = shift; |
360
|
92
|
|
|
|
|
3851
|
require HTTP::Headers::Util; |
361
|
92
|
|
|
|
|
184
|
my $h = $self->{'content-type'}; |
362
|
92
|
50
|
|
|
|
204
|
$h = $h->[0] if ref($h); |
363
|
92
|
100
|
|
|
|
195
|
$h = "" unless defined $h; |
364
|
92
|
|
|
|
|
242
|
my @v = HTTP::Headers::Util::split_header_words($h); |
365
|
92
|
100
|
|
|
|
200
|
if (@v) { |
366
|
90
|
|
|
|
|
129
|
my($ct, undef, %ct_param) = @{$v[0]}; |
|
90
|
|
|
|
|
232
|
|
367
|
90
|
|
|
|
|
168
|
my $charset = $ct_param{charset}; |
368
|
90
|
50
|
|
|
|
174
|
if ($ct) { |
369
|
90
|
|
|
|
|
183
|
$ct = lc($ct); |
370
|
90
|
|
|
|
|
190
|
$ct =~ s/\s+//; |
371
|
|
|
|
|
|
|
} |
372
|
90
|
100
|
|
|
|
193
|
if ($charset) { |
373
|
16
|
|
|
|
|
31
|
$charset = uc($charset); |
374
|
16
|
|
|
|
|
32
|
$charset =~ s/^\s+//; $charset =~ s/\s+\z//; |
|
16
|
|
|
|
|
37
|
|
375
|
16
|
50
|
|
|
|
36
|
undef($charset) if $charset eq ""; |
376
|
|
|
|
|
|
|
} |
377
|
90
|
50
|
|
|
|
172
|
return $ct, $charset if wantarray; |
378
|
90
|
|
|
|
|
640
|
return $charset; |
379
|
|
|
|
|
|
|
} |
380
|
2
|
50
|
|
|
|
6
|
return undef, undef if wantarray; |
381
|
2
|
|
|
|
|
11
|
return undef; |
382
|
|
|
|
|
|
|
} |
383
|
|
|
|
|
|
|
|
384
|
|
|
|
|
|
|
sub content_is_text { |
385
|
107
|
|
|
107
|
1
|
195
|
my $self = shift; |
386
|
107
|
|
|
|
|
261
|
return $self->content_type =~ m,^text/,; |
387
|
|
|
|
|
|
|
} |
388
|
|
|
|
|
|
|
|
389
|
|
|
|
|
|
|
sub content_is_html { |
390
|
35
|
|
|
35
|
1
|
65
|
my $self = shift; |
391
|
35
|
|
100
|
|
|
63
|
return $self->content_type eq 'text/html' || $self->content_is_xhtml; |
392
|
|
|
|
|
|
|
} |
393
|
|
|
|
|
|
|
|
394
|
|
|
|
|
|
|
sub content_is_xhtml { |
395
|
36
|
|
|
36
|
1
|
76
|
my $ct = shift->content_type; |
396
|
36
|
|
100
|
|
|
271
|
return $ct eq "application/xhtml+xml" || |
397
|
|
|
|
|
|
|
$ct eq "application/vnd.wap.xhtml+xml"; |
398
|
|
|
|
|
|
|
} |
399
|
|
|
|
|
|
|
|
400
|
|
|
|
|
|
|
sub content_is_xml { |
401
|
84
|
|
|
84
|
1
|
176
|
my $ct = shift->content_type; |
402
|
84
|
100
|
|
|
|
225
|
return 1 if $ct eq "text/xml"; |
403
|
83
|
100
|
|
|
|
298
|
return 1 if $ct eq "application/xml"; |
404
|
39
|
100
|
|
|
|
95
|
return 1 if $ct =~ /\+xml$/; |
405
|
37
|
|
|
|
|
166
|
return 0; |
406
|
|
|
|
|
|
|
} |
407
|
|
|
|
|
|
|
|
408
|
|
|
|
|
|
|
sub referer { |
409
|
9
|
|
|
9
|
1
|
12914
|
my $self = shift; |
410
|
9
|
100
|
100
|
|
|
94
|
if (@_ && $_[0] =~ /#/) { |
411
|
|
|
|
|
|
|
# Strip fragment per RFC 2616, section 14.36. |
412
|
2
|
|
|
|
|
13
|
my $uri = shift; |
413
|
2
|
100
|
|
|
|
9
|
if (ref($uri)) { |
414
|
1
|
|
|
|
|
7
|
$uri = $uri->clone; |
415
|
1
|
|
|
|
|
13
|
$uri->fragment(undef); |
416
|
|
|
|
|
|
|
} |
417
|
|
|
|
|
|
|
else { |
418
|
1
|
|
|
|
|
6
|
$uri =~ s/\#.*//; |
419
|
|
|
|
|
|
|
} |
420
|
2
|
|
|
|
|
21
|
unshift @_, $uri; |
421
|
|
|
|
|
|
|
} |
422
|
9
|
|
|
|
|
24
|
($self->_header('Referer', @_))[0]; |
423
|
|
|
|
|
|
|
} |
424
|
|
|
|
|
|
|
*referrer = \&referer; # on tchrist's request |
425
|
|
|
|
|
|
|
|
426
|
3
|
|
|
3
|
1
|
11
|
sub title { (shift->_header('Title', @_))[0] } |
427
|
3
|
|
|
3
|
1
|
11
|
sub content_encoding { (shift->_header('Content-Encoding', @_))[0] } |
428
|
3
|
|
|
3
|
1
|
524
|
sub content_language { (shift->_header('Content-Language', @_))[0] } |
429
|
12
|
|
|
12
|
1
|
44
|
sub content_length { (shift->_header('Content-Length', @_))[0] } |
430
|
|
|
|
|
|
|
|
431
|
4
|
|
|
4
|
1
|
18
|
sub user_agent { (shift->_header('User-Agent', @_))[0] } |
432
|
3
|
|
|
3
|
1
|
12
|
sub server { (shift->_header('Server', @_))[0] } |
433
|
|
|
|
|
|
|
|
434
|
1
|
|
|
1
|
1
|
5
|
sub from { (shift->_header('From', @_))[0] } |
435
|
3
|
|
|
3
|
0
|
15
|
sub warning { (shift->_header('Warning', @_))[0] } |
436
|
|
|
|
|
|
|
|
437
|
3
|
|
|
3
|
1
|
10
|
sub www_authenticate { (shift->_header('WWW-Authenticate', @_))[0] } |
438
|
1
|
|
|
1
|
1
|
514
|
sub authorization { (shift->_header('Authorization', @_))[0] } |
439
|
|
|
|
|
|
|
|
440
|
3
|
|
|
3
|
1
|
12
|
sub proxy_authenticate { (shift->_header('Proxy-Authenticate', @_))[0] } |
441
|
1
|
|
|
1
|
1
|
561
|
sub proxy_authorization { (shift->_header('Proxy-Authorization', @_))[0] } |
442
|
|
|
|
|
|
|
|
443
|
9
|
|
|
9
|
1
|
725
|
sub authorization_basic { shift->_basic_auth("Authorization", @_) } |
444
|
2
|
|
|
2
|
1
|
554
|
sub proxy_authorization_basic { shift->_basic_auth("Proxy-Authorization", @_) } |
445
|
|
|
|
|
|
|
|
446
|
|
|
|
|
|
|
sub _basic_auth { |
447
|
11
|
|
|
11
|
|
1006
|
require MIME::Base64; |
448
|
11
|
|
|
|
|
1394
|
my($self, $h, $user, $passwd) = @_; |
449
|
11
|
|
|
|
|
31
|
my($old) = $self->_header($h); |
450
|
11
|
100
|
|
|
|
27
|
if (defined $user) { |
451
|
5
|
100
|
|
|
|
159
|
Carp::croak("Basic authorization user name can't contain ':'") |
452
|
|
|
|
|
|
|
if $user =~ /:/; |
453
|
4
|
100
|
|
|
|
11
|
$passwd = '' unless defined $passwd; |
454
|
4
|
|
|
|
|
27
|
$self->_header($h => 'Basic ' . |
455
|
|
|
|
|
|
|
MIME::Base64::encode("$user:$passwd", '')); |
456
|
|
|
|
|
|
|
} |
457
|
10
|
100
|
66
|
|
|
72
|
if (defined $old && $old =~ s/^\s*Basic\s+//) { |
458
|
6
|
|
|
|
|
34
|
my $val = MIME::Base64::decode($old); |
459
|
6
|
100
|
|
|
|
24
|
return $val unless wantarray; |
460
|
4
|
|
|
|
|
25
|
return split(/:/, $val, 2); |
461
|
|
|
|
|
|
|
} |
462
|
4
|
|
|
|
|
20
|
return; |
463
|
|
|
|
|
|
|
} |
464
|
|
|
|
|
|
|
|
465
|
|
|
|
|
|
|
|
466
|
|
|
|
|
|
|
1; |
467
|
|
|
|
|
|
|
|
468
|
|
|
|
|
|
|
=pod |
469
|
|
|
|
|
|
|
|
470
|
|
|
|
|
|
|
=encoding UTF-8 |
471
|
|
|
|
|
|
|
|
472
|
|
|
|
|
|
|
=head1 NAME |
473
|
|
|
|
|
|
|
|
474
|
|
|
|
|
|
|
HTTP::Headers - Class encapsulating HTTP Message headers |
475
|
|
|
|
|
|
|
|
476
|
|
|
|
|
|
|
=head1 VERSION |
477
|
|
|
|
|
|
|
|
478
|
|
|
|
|
|
|
version 6.43 |
479
|
|
|
|
|
|
|
|
480
|
|
|
|
|
|
|
=head1 SYNOPSIS |
481
|
|
|
|
|
|
|
|
482
|
|
|
|
|
|
|
require HTTP::Headers; |
483
|
|
|
|
|
|
|
$h = HTTP::Headers->new; |
484
|
|
|
|
|
|
|
|
485
|
|
|
|
|
|
|
$h->header('Content-Type' => 'text/plain'); # set |
486
|
|
|
|
|
|
|
$ct = $h->header('Content-Type'); # get |
487
|
|
|
|
|
|
|
$h->remove_header('Content-Type'); # delete |
488
|
|
|
|
|
|
|
|
489
|
|
|
|
|
|
|
=head1 DESCRIPTION |
490
|
|
|
|
|
|
|
|
491
|
|
|
|
|
|
|
The C class encapsulates HTTP-style message headers. |
492
|
|
|
|
|
|
|
The headers consist of attribute-value pairs also called fields, which |
493
|
|
|
|
|
|
|
may be repeated, and which are printed in a particular order. The |
494
|
|
|
|
|
|
|
field names are cases insensitive. |
495
|
|
|
|
|
|
|
|
496
|
|
|
|
|
|
|
Instances of this class are usually created as member variables of the |
497
|
|
|
|
|
|
|
C and C classes, internal to the |
498
|
|
|
|
|
|
|
library. |
499
|
|
|
|
|
|
|
|
500
|
|
|
|
|
|
|
The following methods are available: |
501
|
|
|
|
|
|
|
|
502
|
|
|
|
|
|
|
=over 4 |
503
|
|
|
|
|
|
|
|
504
|
|
|
|
|
|
|
=item $h = HTTP::Headers->new |
505
|
|
|
|
|
|
|
|
506
|
|
|
|
|
|
|
Constructs a new C object. You might pass some initial |
507
|
|
|
|
|
|
|
attribute-value pairs as parameters to the constructor. I: |
508
|
|
|
|
|
|
|
|
509
|
|
|
|
|
|
|
$h = HTTP::Headers->new( |
510
|
|
|
|
|
|
|
Date => 'Thu, 03 Feb 1994 00:00:00 GMT', |
511
|
|
|
|
|
|
|
Content_Type => 'text/html; version=3.2', |
512
|
|
|
|
|
|
|
Content_Base => 'http://www.perl.org/'); |
513
|
|
|
|
|
|
|
|
514
|
|
|
|
|
|
|
The constructor arguments are passed to the C |
515
|
|
|
|
|
|
|
described below. |
516
|
|
|
|
|
|
|
|
517
|
|
|
|
|
|
|
=item $h->clone |
518
|
|
|
|
|
|
|
|
519
|
|
|
|
|
|
|
Returns a copy of this C object. |
520
|
|
|
|
|
|
|
|
521
|
|
|
|
|
|
|
=item $h->header( $field ) |
522
|
|
|
|
|
|
|
|
523
|
|
|
|
|
|
|
=item $h->header( $field => $value ) |
524
|
|
|
|
|
|
|
|
525
|
|
|
|
|
|
|
=item $h->header( $f1 => $v1, $f2 => $v2, ... ) |
526
|
|
|
|
|
|
|
|
527
|
|
|
|
|
|
|
Get or set the value of one or more header fields. The header field |
528
|
|
|
|
|
|
|
name ($field) is not case sensitive. To make the life easier for perl |
529
|
|
|
|
|
|
|
users who wants to avoid quoting before the => operator, you can use |
530
|
|
|
|
|
|
|
'_' as a replacement for '-' in header names. |
531
|
|
|
|
|
|
|
|
532
|
|
|
|
|
|
|
The header() method accepts multiple ($field => $value) pairs, which |
533
|
|
|
|
|
|
|
means that you can update several fields with a single invocation. |
534
|
|
|
|
|
|
|
|
535
|
|
|
|
|
|
|
The $value argument may be a plain string or a reference to an array |
536
|
|
|
|
|
|
|
of strings for a multi-valued field. If the $value is provided as |
537
|
|
|
|
|
|
|
C then the field is removed. If the $value is not given, then |
538
|
|
|
|
|
|
|
that header field will remain unchanged. In addition to being a string, |
539
|
|
|
|
|
|
|
$value may be something that stringifies. |
540
|
|
|
|
|
|
|
|
541
|
|
|
|
|
|
|
The old value (or values) of the last of the header fields is returned. |
542
|
|
|
|
|
|
|
If no such field exists C will be returned. |
543
|
|
|
|
|
|
|
|
544
|
|
|
|
|
|
|
A multi-valued field will be returned as separate values in list |
545
|
|
|
|
|
|
|
context and will be concatenated with ", " as separator in scalar |
546
|
|
|
|
|
|
|
context. The HTTP spec (RFC 2616) promises that joining multiple |
547
|
|
|
|
|
|
|
values in this way will not change the semantic of a header field, but |
548
|
|
|
|
|
|
|
in practice there are cases like old-style Netscape cookies (see |
549
|
|
|
|
|
|
|
L) where "," is used as part of the syntax of a single |
550
|
|
|
|
|
|
|
field value. |
551
|
|
|
|
|
|
|
|
552
|
|
|
|
|
|
|
Examples: |
553
|
|
|
|
|
|
|
|
554
|
|
|
|
|
|
|
$header->header(MIME_Version => '1.0', |
555
|
|
|
|
|
|
|
User_Agent => 'My-Web-Client/0.01'); |
556
|
|
|
|
|
|
|
$header->header(Accept => "text/html, text/plain, image/*"); |
557
|
|
|
|
|
|
|
$header->header(Accept => [qw(text/html text/plain image/*)]); |
558
|
|
|
|
|
|
|
@accepts = $header->header('Accept'); # get multiple values |
559
|
|
|
|
|
|
|
$accepts = $header->header('Accept'); # get values as a single string |
560
|
|
|
|
|
|
|
|
561
|
|
|
|
|
|
|
=item $h->push_header( $field => $value ) |
562
|
|
|
|
|
|
|
|
563
|
|
|
|
|
|
|
=item $h->push_header( $f1 => $v1, $f2 => $v2, ... ) |
564
|
|
|
|
|
|
|
|
565
|
|
|
|
|
|
|
Add a new field value for the specified header field. Previous values |
566
|
|
|
|
|
|
|
for the same field are retained. |
567
|
|
|
|
|
|
|
|
568
|
|
|
|
|
|
|
As for the header() method, the field name ($field) is not case |
569
|
|
|
|
|
|
|
sensitive and '_' can be used as a replacement for '-'. |
570
|
|
|
|
|
|
|
|
571
|
|
|
|
|
|
|
The $value argument may be a scalar or a reference to a list of |
572
|
|
|
|
|
|
|
scalars. |
573
|
|
|
|
|
|
|
|
574
|
|
|
|
|
|
|
$header->push_header(Accept => 'image/jpeg'); |
575
|
|
|
|
|
|
|
$header->push_header(Accept => [map "image/$_", qw(gif png tiff)]); |
576
|
|
|
|
|
|
|
|
577
|
|
|
|
|
|
|
=item $h->init_header( $field => $value ) |
578
|
|
|
|
|
|
|
|
579
|
|
|
|
|
|
|
Set the specified header to the given value, but only if no previous |
580
|
|
|
|
|
|
|
value for that field is set. |
581
|
|
|
|
|
|
|
|
582
|
|
|
|
|
|
|
The header field name ($field) is not case sensitive and '_' |
583
|
|
|
|
|
|
|
can be used as a replacement for '-'. |
584
|
|
|
|
|
|
|
|
585
|
|
|
|
|
|
|
The $value argument may be a scalar or a reference to a list of |
586
|
|
|
|
|
|
|
scalars. |
587
|
|
|
|
|
|
|
|
588
|
|
|
|
|
|
|
=item $h->remove_header( $field, ... ) |
589
|
|
|
|
|
|
|
|
590
|
|
|
|
|
|
|
This function removes the header fields with the specified names. |
591
|
|
|
|
|
|
|
|
592
|
|
|
|
|
|
|
The header field names ($field) are not case sensitive and '_' |
593
|
|
|
|
|
|
|
can be used as a replacement for '-'. |
594
|
|
|
|
|
|
|
|
595
|
|
|
|
|
|
|
The return value is the values of the fields removed. In scalar |
596
|
|
|
|
|
|
|
context the number of fields removed is returned. |
597
|
|
|
|
|
|
|
|
598
|
|
|
|
|
|
|
Note that if you pass in multiple field names then it is generally not |
599
|
|
|
|
|
|
|
possible to tell which of the returned values belonged to which field. |
600
|
|
|
|
|
|
|
|
601
|
|
|
|
|
|
|
=item $h->remove_content_headers |
602
|
|
|
|
|
|
|
|
603
|
|
|
|
|
|
|
This will remove all the header fields used to describe the content of |
604
|
|
|
|
|
|
|
a message. All header field names prefixed with C fall |
605
|
|
|
|
|
|
|
into this category, as well as C, C and |
606
|
|
|
|
|
|
|
C. RFC 2616 denotes these fields as I
|
607
|
|
|
|
|
|
|
Fields>. |
608
|
|
|
|
|
|
|
|
609
|
|
|
|
|
|
|
The return value is a new C object that contains the |
610
|
|
|
|
|
|
|
removed headers only. |
611
|
|
|
|
|
|
|
|
612
|
|
|
|
|
|
|
=item $h->clear |
613
|
|
|
|
|
|
|
|
614
|
|
|
|
|
|
|
This will remove all header fields. |
615
|
|
|
|
|
|
|
|
616
|
|
|
|
|
|
|
=item $h->header_field_names |
617
|
|
|
|
|
|
|
|
618
|
|
|
|
|
|
|
Returns the list of distinct names for the fields present in the |
619
|
|
|
|
|
|
|
header. The field names have case as suggested by HTTP spec, and the |
620
|
|
|
|
|
|
|
names are returned in the recommended "Good Practice" order. |
621
|
|
|
|
|
|
|
|
622
|
|
|
|
|
|
|
In scalar context return the number of distinct field names. |
623
|
|
|
|
|
|
|
|
624
|
|
|
|
|
|
|
=item $h->scan( \&process_header_field ) |
625
|
|
|
|
|
|
|
|
626
|
|
|
|
|
|
|
Apply a subroutine to each header field in turn. The callback routine |
627
|
|
|
|
|
|
|
is called with two parameters; the name of the field and a single |
628
|
|
|
|
|
|
|
value (a string). If a header field is multi-valued, then the |
629
|
|
|
|
|
|
|
routine is called once for each value. The field name passed to the |
630
|
|
|
|
|
|
|
callback routine has case as suggested by HTTP spec, and the headers |
631
|
|
|
|
|
|
|
will be visited in the recommended "Good Practice" order. |
632
|
|
|
|
|
|
|
|
633
|
|
|
|
|
|
|
Any return values of the callback routine are ignored. The loop can |
634
|
|
|
|
|
|
|
be broken by raising an exception (C), but the caller of scan() |
635
|
|
|
|
|
|
|
would have to trap the exception itself. |
636
|
|
|
|
|
|
|
|
637
|
|
|
|
|
|
|
=item $h->flatten() |
638
|
|
|
|
|
|
|
|
639
|
|
|
|
|
|
|
Returns the list of pairs of keys and values. |
640
|
|
|
|
|
|
|
|
641
|
|
|
|
|
|
|
=item $h->as_string |
642
|
|
|
|
|
|
|
|
643
|
|
|
|
|
|
|
=item $h->as_string( $eol ) |
644
|
|
|
|
|
|
|
|
645
|
|
|
|
|
|
|
Return the header fields as a formatted MIME header. Since it |
646
|
|
|
|
|
|
|
internally uses the C method to build the string, the result |
647
|
|
|
|
|
|
|
will use case as suggested by HTTP spec, and it will follow |
648
|
|
|
|
|
|
|
recommended "Good Practice" of ordering the header fields. Long header |
649
|
|
|
|
|
|
|
values are not folded. |
650
|
|
|
|
|
|
|
|
651
|
|
|
|
|
|
|
The optional $eol parameter specifies the line ending sequence to |
652
|
|
|
|
|
|
|
use. The default is "\n". Embedded "\n" characters in header field |
653
|
|
|
|
|
|
|
values will be substituted with this line ending sequence. |
654
|
|
|
|
|
|
|
|
655
|
|
|
|
|
|
|
=back |
656
|
|
|
|
|
|
|
|
657
|
|
|
|
|
|
|
=head1 CONVENIENCE METHODS |
658
|
|
|
|
|
|
|
|
659
|
|
|
|
|
|
|
The most frequently used headers can also be accessed through the |
660
|
|
|
|
|
|
|
following convenience methods. Most of these methods can both be used to read |
661
|
|
|
|
|
|
|
and to set the value of a header. The header value is set if you pass |
662
|
|
|
|
|
|
|
an argument to the method. The old header value is always returned. |
663
|
|
|
|
|
|
|
If the given header did not exist then C is returned. |
664
|
|
|
|
|
|
|
|
665
|
|
|
|
|
|
|
Methods that deal with dates/times always convert their value to system |
666
|
|
|
|
|
|
|
time (seconds since Jan 1, 1970) and they also expect this kind of |
667
|
|
|
|
|
|
|
value when the header value is set. |
668
|
|
|
|
|
|
|
|
669
|
|
|
|
|
|
|
=over 4 |
670
|
|
|
|
|
|
|
|
671
|
|
|
|
|
|
|
=item $h->date |
672
|
|
|
|
|
|
|
|
673
|
|
|
|
|
|
|
This header represents the date and time at which the message was |
674
|
|
|
|
|
|
|
originated. I: |
675
|
|
|
|
|
|
|
|
676
|
|
|
|
|
|
|
$h->date(time); # set current date |
677
|
|
|
|
|
|
|
|
678
|
|
|
|
|
|
|
=item $h->expires |
679
|
|
|
|
|
|
|
|
680
|
|
|
|
|
|
|
This header gives the date and time after which the entity should be |
681
|
|
|
|
|
|
|
considered stale. |
682
|
|
|
|
|
|
|
|
683
|
|
|
|
|
|
|
=item $h->if_modified_since |
684
|
|
|
|
|
|
|
|
685
|
|
|
|
|
|
|
=item $h->if_unmodified_since |
686
|
|
|
|
|
|
|
|
687
|
|
|
|
|
|
|
These header fields are used to make a request conditional. If the requested |
688
|
|
|
|
|
|
|
resource has (or has not) been modified since the time specified in this field, |
689
|
|
|
|
|
|
|
then the server will return a C<304 Not Modified> response instead of |
690
|
|
|
|
|
|
|
the document itself. |
691
|
|
|
|
|
|
|
|
692
|
|
|
|
|
|
|
=item $h->last_modified |
693
|
|
|
|
|
|
|
|
694
|
|
|
|
|
|
|
This header indicates the date and time at which the resource was last |
695
|
|
|
|
|
|
|
modified. I: |
696
|
|
|
|
|
|
|
|
697
|
|
|
|
|
|
|
# check if document is more than 1 hour old |
698
|
|
|
|
|
|
|
if (my $last_mod = $h->last_modified) { |
699
|
|
|
|
|
|
|
if ($last_mod < time - 60*60) { |
700
|
|
|
|
|
|
|
... |
701
|
|
|
|
|
|
|
} |
702
|
|
|
|
|
|
|
} |
703
|
|
|
|
|
|
|
|
704
|
|
|
|
|
|
|
=item $h->content_type |
705
|
|
|
|
|
|
|
|
706
|
|
|
|
|
|
|
The Content-Type header field indicates the media type of the message |
707
|
|
|
|
|
|
|
content. I: |
708
|
|
|
|
|
|
|
|
709
|
|
|
|
|
|
|
$h->content_type('text/html'); |
710
|
|
|
|
|
|
|
|
711
|
|
|
|
|
|
|
The value returned will be converted to lower case, and potential |
712
|
|
|
|
|
|
|
parameters will be chopped off and returned as a separate value if in |
713
|
|
|
|
|
|
|
an array context. If there is no such header field, then the empty |
714
|
|
|
|
|
|
|
string is returned. This makes it safe to do the following: |
715
|
|
|
|
|
|
|
|
716
|
|
|
|
|
|
|
if ($h->content_type eq 'text/html') { |
717
|
|
|
|
|
|
|
# we enter this place even if the real header value happens to |
718
|
|
|
|
|
|
|
# be 'TEXT/HTML; version=3.0' |
719
|
|
|
|
|
|
|
... |
720
|
|
|
|
|
|
|
} |
721
|
|
|
|
|
|
|
|
722
|
|
|
|
|
|
|
=item $h->content_type_charset |
723
|
|
|
|
|
|
|
|
724
|
|
|
|
|
|
|
Returns the upper-cased charset specified in the Content-Type header. In list |
725
|
|
|
|
|
|
|
context return the lower-cased bare content type followed by the upper-cased |
726
|
|
|
|
|
|
|
charset. Both values will be C if not specified in the header. |
727
|
|
|
|
|
|
|
|
728
|
|
|
|
|
|
|
=item $h->content_is_text |
729
|
|
|
|
|
|
|
|
730
|
|
|
|
|
|
|
Returns TRUE if the Content-Type header field indicate that the |
731
|
|
|
|
|
|
|
content is textual. |
732
|
|
|
|
|
|
|
|
733
|
|
|
|
|
|
|
=item $h->content_is_html |
734
|
|
|
|
|
|
|
|
735
|
|
|
|
|
|
|
Returns TRUE if the Content-Type header field indicate that the |
736
|
|
|
|
|
|
|
content is some kind of HTML (including XHTML). This method can't be |
737
|
|
|
|
|
|
|
used to set Content-Type. |
738
|
|
|
|
|
|
|
|
739
|
|
|
|
|
|
|
=item $h->content_is_xhtml |
740
|
|
|
|
|
|
|
|
741
|
|
|
|
|
|
|
Returns TRUE if the Content-Type header field indicate that the |
742
|
|
|
|
|
|
|
content is XHTML. This method can't be used to set Content-Type. |
743
|
|
|
|
|
|
|
|
744
|
|
|
|
|
|
|
=item $h->content_is_xml |
745
|
|
|
|
|
|
|
|
746
|
|
|
|
|
|
|
Returns TRUE if the Content-Type header field indicate that the |
747
|
|
|
|
|
|
|
content is XML. This method can't be used to set Content-Type. |
748
|
|
|
|
|
|
|
|
749
|
|
|
|
|
|
|
=item $h->content_encoding |
750
|
|
|
|
|
|
|
|
751
|
|
|
|
|
|
|
The Content-Encoding header field is used as a modifier to the |
752
|
|
|
|
|
|
|
media type. When present, its value indicates what additional |
753
|
|
|
|
|
|
|
encoding mechanism has been applied to the resource. |
754
|
|
|
|
|
|
|
|
755
|
|
|
|
|
|
|
=item $h->content_length |
756
|
|
|
|
|
|
|
|
757
|
|
|
|
|
|
|
A decimal number indicating the size in bytes of the message content. |
758
|
|
|
|
|
|
|
|
759
|
|
|
|
|
|
|
=item $h->content_language |
760
|
|
|
|
|
|
|
|
761
|
|
|
|
|
|
|
The natural language(s) of the intended audience for the message |
762
|
|
|
|
|
|
|
content. The value is one or more language tags as defined by RFC |
763
|
|
|
|
|
|
|
1766. Eg. "no" for some kind of Norwegian and "en-US" for English the |
764
|
|
|
|
|
|
|
way it is written in the US. |
765
|
|
|
|
|
|
|
|
766
|
|
|
|
|
|
|
=item $h->title |
767
|
|
|
|
|
|
|
|
768
|
|
|
|
|
|
|
The title of the document. In libwww-perl this header will be |
769
|
|
|
|
|
|
|
initialized automatically from the ETITLE>...E/TITLE> element |
770
|
|
|
|
|
|
|
of HTML documents. I
|
771
|
|
|
|
|
|
|
standard.> |
772
|
|
|
|
|
|
|
|
773
|
|
|
|
|
|
|
=item $h->user_agent |
774
|
|
|
|
|
|
|
|
775
|
|
|
|
|
|
|
This header field is used in request messages and contains information |
776
|
|
|
|
|
|
|
about the user agent originating the request. I: |
777
|
|
|
|
|
|
|
|
778
|
|
|
|
|
|
|
$h->user_agent('Mozilla/5.0 (compatible; MSIE 7.0; Windows NT 6.0)'); |
779
|
|
|
|
|
|
|
|
780
|
|
|
|
|
|
|
=item $h->server |
781
|
|
|
|
|
|
|
|
782
|
|
|
|
|
|
|
The server header field contains information about the software being |
783
|
|
|
|
|
|
|
used by the originating server program handling the request. |
784
|
|
|
|
|
|
|
|
785
|
|
|
|
|
|
|
=item $h->from |
786
|
|
|
|
|
|
|
|
787
|
|
|
|
|
|
|
This header should contain an Internet e-mail address for the human |
788
|
|
|
|
|
|
|
user who controls the requesting user agent. The address should be |
789
|
|
|
|
|
|
|
machine-usable, as defined by RFC822. E.g.: |
790
|
|
|
|
|
|
|
|
791
|
|
|
|
|
|
|
$h->from('King Kong '); |
792
|
|
|
|
|
|
|
|
793
|
|
|
|
|
|
|
I |
794
|
|
|
|
|
|
|
|
795
|
|
|
|
|
|
|
=item $h->referer |
796
|
|
|
|
|
|
|
|
797
|
|
|
|
|
|
|
Used to specify the address (URI) of the document from which the |
798
|
|
|
|
|
|
|
requested resource address was obtained. |
799
|
|
|
|
|
|
|
|
800
|
|
|
|
|
|
|
The "Free On-line Dictionary of Computing" as this to say about the |
801
|
|
|
|
|
|
|
word I: |
802
|
|
|
|
|
|
|
|
803
|
|
|
|
|
|
|
A misspelling of "referrer" which |
804
|
|
|
|
|
|
|
somehow made it into the {HTTP} standard. A given {web |
805
|
|
|
|
|
|
|
page}'s referer (sic) is the {URL} of whatever web page |
806
|
|
|
|
|
|
|
contains the link that the user followed to the current |
807
|
|
|
|
|
|
|
page. Most browsers pass this information as part of a |
808
|
|
|
|
|
|
|
request. |
809
|
|
|
|
|
|
|
|
810
|
|
|
|
|
|
|
(1998-10-19) |
811
|
|
|
|
|
|
|
|
812
|
|
|
|
|
|
|
By popular demand C exists as an alias for this method so you |
813
|
|
|
|
|
|
|
can avoid this misspelling in your programs and still send the right |
814
|
|
|
|
|
|
|
thing on the wire. |
815
|
|
|
|
|
|
|
|
816
|
|
|
|
|
|
|
When setting the referrer, this method removes the fragment from the |
817
|
|
|
|
|
|
|
given URI if it is present, as mandated by RFC2616. Note that |
818
|
|
|
|
|
|
|
the removal does I happen automatically if using the header(), |
819
|
|
|
|
|
|
|
push_header() or init_header() methods to set the referrer. |
820
|
|
|
|
|
|
|
|
821
|
|
|
|
|
|
|
=item $h->www_authenticate |
822
|
|
|
|
|
|
|
|
823
|
|
|
|
|
|
|
This header must be included as part of a C<401 Unauthorized> response. |
824
|
|
|
|
|
|
|
The field value consist of a challenge that indicates the |
825
|
|
|
|
|
|
|
authentication scheme and parameters applicable to the requested URI. |
826
|
|
|
|
|
|
|
|
827
|
|
|
|
|
|
|
=item $h->proxy_authenticate |
828
|
|
|
|
|
|
|
|
829
|
|
|
|
|
|
|
This header must be included in a C<407 Proxy Authentication Required> |
830
|
|
|
|
|
|
|
response. |
831
|
|
|
|
|
|
|
|
832
|
|
|
|
|
|
|
=item $h->authorization |
833
|
|
|
|
|
|
|
|
834
|
|
|
|
|
|
|
=item $h->proxy_authorization |
835
|
|
|
|
|
|
|
|
836
|
|
|
|
|
|
|
A user agent that wishes to authenticate itself with a server or a |
837
|
|
|
|
|
|
|
proxy, may do so by including these headers. |
838
|
|
|
|
|
|
|
|
839
|
|
|
|
|
|
|
=item $h->authorization_basic |
840
|
|
|
|
|
|
|
|
841
|
|
|
|
|
|
|
This method is used to get or set an authorization header that use the |
842
|
|
|
|
|
|
|
"Basic Authentication Scheme". In array context it will return two |
843
|
|
|
|
|
|
|
values; the user name and the password. In scalar context it will |
844
|
|
|
|
|
|
|
return I<"uname:password"> as a single string value. |
845
|
|
|
|
|
|
|
|
846
|
|
|
|
|
|
|
When used to set the header value, it expects two arguments. I: |
847
|
|
|
|
|
|
|
|
848
|
|
|
|
|
|
|
$h->authorization_basic($uname, $password); |
849
|
|
|
|
|
|
|
|
850
|
|
|
|
|
|
|
The method will croak if the $uname contains a colon ':'. |
851
|
|
|
|
|
|
|
|
852
|
|
|
|
|
|
|
=item $h->proxy_authorization_basic |
853
|
|
|
|
|
|
|
|
854
|
|
|
|
|
|
|
Same as authorization_basic() but will set the "Proxy-Authorization" |
855
|
|
|
|
|
|
|
header instead. |
856
|
|
|
|
|
|
|
|
857
|
|
|
|
|
|
|
=back |
858
|
|
|
|
|
|
|
|
859
|
|
|
|
|
|
|
=head1 NON-CANONICALIZED FIELD NAMES |
860
|
|
|
|
|
|
|
|
861
|
|
|
|
|
|
|
The header field name spelling is normally canonicalized including the |
862
|
|
|
|
|
|
|
'_' to '-' translation. There are some application where this is not |
863
|
|
|
|
|
|
|
appropriate. Prefixing field names with ':' allow you to force a |
864
|
|
|
|
|
|
|
specific spelling. For example if you really want a header field name |
865
|
|
|
|
|
|
|
to show up as C instead of "Foo-Bar", you might set it like |
866
|
|
|
|
|
|
|
this: |
867
|
|
|
|
|
|
|
|
868
|
|
|
|
|
|
|
$h->header(":foo_bar" => 1); |
869
|
|
|
|
|
|
|
|
870
|
|
|
|
|
|
|
These field names are returned with the ':' intact for |
871
|
|
|
|
|
|
|
$h->header_field_names and the $h->scan callback, but the colons do |
872
|
|
|
|
|
|
|
not show in $h->as_string. |
873
|
|
|
|
|
|
|
|
874
|
|
|
|
|
|
|
=head1 AUTHOR |
875
|
|
|
|
|
|
|
|
876
|
|
|
|
|
|
|
Gisle Aas |
877
|
|
|
|
|
|
|
|
878
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
879
|
|
|
|
|
|
|
|
880
|
|
|
|
|
|
|
This software is copyright (c) 1994 by Gisle Aas. |
881
|
|
|
|
|
|
|
|
882
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
883
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
884
|
|
|
|
|
|
|
|
885
|
|
|
|
|
|
|
=cut |
886
|
|
|
|
|
|
|
|
887
|
|
|
|
|
|
|
__END__ |