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