source: main/trunk/greenstone2/perllib/cpan/HTTP/Headers.pm@ 27174

Last change on this file since 27174 was 27174, checked in by davidb, 11 years ago

Perl modules from CPAN that are used in supporting activate.pl, but not part of the Perl core. Only PMs included.

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