home *** CD-ROM | disk | FTP | other *** search
/ Netrunner 2004 October / NETRUNNER0410.ISO / regular / ActivePerl-5.8.4.810-MSWin32-x86.msi / _f3bfe19c6a87e8f476745dc98452c4ee < prev    next >
Text File  |  2004-06-01  |  21KB  |  708 lines

  1. package HTTP::Headers;
  2.  
  3. # $Id: Headers.pm,v 1.59 2004/04/10 21:55:14 gisle Exp $
  4.  
  5. use strict;
  6. use Carp ();
  7.  
  8. use vars qw($VERSION $TRANSLATE_UNDERSCORE);
  9. $VERSION = sprintf("%d.%02d", q$Revision: 1.59 $ =~ /(\d+)\.(\d+)/);
  10.  
  11. # The $TRANSLATE_UNDERSCORE variable controls whether '_' can be used
  12. # as a replacement for '-' in header field names.
  13. $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.     my($class) = shift;
  71.     my $self = bless {}, $class;
  72.     $self->header(@_) if @_; # set up initial headers
  73.     $self;
  74. }
  75.  
  76.  
  77. sub header
  78. {
  79.     my $self = shift;
  80.     Carp::croak('Usage: $h->header($field, ...)') unless @_;
  81.     my(@old);
  82.     while (my($field, $val) = splice(@_, 0, 2)) {
  83.     @old = $self->_header($field, $val);
  84.     }
  85.     return @old if wantarray;
  86.     return $old[0] if @old <= 1;
  87.     join(", ", @old);
  88. }
  89.  
  90. sub clear
  91. {
  92.     my $self = shift;
  93.     %$self = ();
  94. }
  95.  
  96.  
  97. sub push_header
  98. {
  99.     Carp::croak('Usage: $h->push_header($field, $val)') if @_ != 3;
  100.     shift->_header(@_, 'PUSH');
  101. }
  102.  
  103.  
  104. sub init_header
  105. {
  106.     Carp::croak('Usage: $h->init_header($field, $val)') if @_ != 3;
  107.     shift->_header(@_, 'INIT');
  108. }
  109.  
  110.  
  111. sub remove_header
  112. {
  113.     my($self, @fields) = @_;
  114.     my $field;
  115.     my @values;
  116.     foreach $field (@fields) {
  117.     $field =~ tr/_/-/ if $TRANSLATE_UNDERSCORE;
  118.     my $v = delete $self->{lc $field};
  119.     push(@values, ref($v) eq 'ARRAY' ? @$v : $v) if defined $v;
  120.     }
  121.     return @values;
  122. }
  123.  
  124. sub remove_content_headers
  125. {
  126.     my $self = shift;
  127.     unless (defined(wantarray)) {
  128.     # fast branch that does not create return object
  129.     delete @$self{grep $entity_header{$_} || /^content-/, keys %$self};
  130.     return;
  131.     }
  132.  
  133.     my $c = ref($self)->new;
  134.     for my $f (grep $entity_header{$_} || /^content-/, keys %$self) {
  135.     $c->{$f} = delete $self->{$f};
  136.     }
  137.     $c;
  138. }
  139.  
  140.  
  141. sub _header
  142. {
  143.     my($self, $field, $val, $op) = @_;
  144.     $field =~ tr/_/-/ if $TRANSLATE_UNDERSCORE;
  145.  
  146.     # $push is only used interally sub push_header
  147.     Carp::croak('Need a field name') unless length($field);
  148.  
  149.     my $lc_field = lc $field;
  150.     unless(defined $standard_case{$lc_field}) {
  151.     # generate a %standard_case entry for this field
  152.     $field =~ s/\b(\w)/\u$1/g;
  153.     $standard_case{$lc_field} = $field;
  154.     }
  155.  
  156.     my $h = $self->{$lc_field};
  157.     my @old = ref($h) eq 'ARRAY' ? @$h : (defined($h) ? ($h) : ());
  158.  
  159.     $op ||= "";
  160.     $val = undef if $op eq 'INIT' && @old;
  161.     if (defined($val)) {
  162.     my @new = ($op eq 'PUSH') ? @old : ();
  163.     if (ref($val) ne 'ARRAY') {
  164.         push(@new, $val);
  165.     }
  166.     else {
  167.         push(@new, @$val);
  168.     }
  169.     $self->{$lc_field} = @new > 1 ? \@new : $new[0];
  170.     }
  171.     @old;
  172. }
  173.  
  174.  
  175. # Compare function which makes it easy to sort headers in the
  176. # recommended "Good Practice" order.
  177. sub _header_cmp
  178. {
  179.     ($header_order{$a} || 999) <=> ($header_order{$b} || 999) || $a cmp $b;
  180. }
  181.  
  182.  
  183. sub header_field_names {
  184.     my $self = shift;
  185.     return map $standard_case{$_}, sort _header_cmp keys %$self
  186.     if wantarray;
  187.     return keys %$self;
  188. }
  189.  
  190.  
  191. sub scan
  192. {
  193.     my($self, $sub) = @_;
  194.     my $key;
  195.     foreach $key (sort _header_cmp keys %$self) {
  196.         next if $key =~ /^_/;
  197.     my $vals = $self->{$key};
  198.     if (ref($vals) eq 'ARRAY') {
  199.         my $val;
  200.         for $val (@$vals) {
  201.         &$sub($standard_case{$key} || $key, $val);
  202.         }
  203.     }
  204.     else {
  205.         &$sub($standard_case{$key} || $key, $vals);
  206.     }
  207.     }
  208. }
  209.  
  210.  
  211. sub as_string
  212. {
  213.     my($self, $endl) = @_;
  214.     $endl = "\n" unless defined $endl;
  215.  
  216.     my @result = ();
  217.     $self->scan(sub {
  218.     my($field, $val) = @_;
  219.     if ($val =~ /\n/) {
  220.         # must handle header values with embedded newlines with care
  221.         $val =~ s/\s+$//;          # trailing newlines and space must go
  222.         $val =~ s/\n\n+/\n/g;      # no empty lines
  223.         $val =~ s/\n([^\040\t])/\n $1/g;  # intial space for continuation
  224.         $val =~ s/\n/$endl/g;      # substitute with requested line ending
  225.     }
  226.     push(@result, "$field: $val");
  227.     });
  228.  
  229.     join($endl, @result, '');
  230. }
  231.  
  232.  
  233. sub clone
  234. {
  235.     my $self = shift;
  236.     my $clone = new HTTP::Headers;
  237.     $self->scan(sub { $clone->push_header(@_);} );
  238.     $clone;
  239. }
  240.  
  241.  
  242. sub _date_header
  243. {
  244.     require HTTP::Date;
  245.     my($self, $header, $time) = @_;
  246.     my($old) = $self->_header($header);
  247.     if (defined $time) {
  248.     $self->_header($header, HTTP::Date::time2str($time));
  249.     }
  250.     HTTP::Date::str2time($old);
  251. }
  252.  
  253.  
  254. sub date                { shift->_date_header('Date',                @_); }
  255. sub expires             { shift->_date_header('Expires',             @_); }
  256. sub if_modified_since   { shift->_date_header('If-Modified-Since',   @_); }
  257. sub if_unmodified_since { shift->_date_header('If-Unmodified-Since', @_); }
  258. sub last_modified       { shift->_date_header('Last-Modified',       @_); }
  259.  
  260. # This is used as a private LWP extention.  The Client-Date header is
  261. # added as a timestamp to a response when it has been received.
  262. sub client_date         { shift->_date_header('Client-Date',         @_); }
  263.  
  264. # The retry_after field is dual format (can also be a expressed as
  265. # number of seconds from now), so we don't provide an easy way to
  266. # access it until we have know how both these interfaces can be
  267. # addressed.  One possibility is to return a negative value for
  268. # relative seconds and a positive value for epoch based time values.
  269. #sub retry_after       { shift->_date_header('Retry-After',       @_); }
  270.  
  271. sub content_type      {
  272.   my $ct = (shift->_header('Content-Type', @_))[0];
  273.   return '' unless defined($ct) && length($ct);
  274.   my @ct = split(/;\s*/, $ct, 2);
  275.   for ($ct[0]) {
  276.       s/\s+//g;
  277.       $_ = lc($_);
  278.   }
  279.   wantarray ? @ct : $ct[0];
  280. }
  281.  
  282. sub referer           {
  283.     my $self = shift;
  284.     if (@_ && $_[0] =~ /#/) {
  285.     # Strip fragment per RFC 2616, section 14.36.
  286.     my $uri = shift;
  287.     if (ref($uri)) {
  288.         $uri = $uri->clone;
  289.         $uri->fragment(undef);
  290.     }
  291.     else {
  292.         $uri =~ s/\#.*//;
  293.     }
  294.     unshift @_, $uri;
  295.     }
  296.     ($self->_header('Referer', @_))[0];
  297. }
  298. *referrer = \&referer;  # on tchrist's request
  299.  
  300. sub title             { (shift->_header('Title',            @_))[0] }
  301. sub content_encoding  { (shift->_header('Content-Encoding', @_))[0] }
  302. sub content_language  { (shift->_header('Content-Language', @_))[0] }
  303. sub content_length    { (shift->_header('Content-Length',   @_))[0] }
  304.  
  305. sub user_agent        { (shift->_header('User-Agent',       @_))[0] }
  306. sub server            { (shift->_header('Server',           @_))[0] }
  307.  
  308. sub from              { (shift->_header('From',             @_))[0] }
  309. sub warning           { (shift->_header('Warning',          @_))[0] }
  310.  
  311. sub www_authenticate  { (shift->_header('WWW-Authenticate', @_))[0] }
  312. sub authorization     { (shift->_header('Authorization',    @_))[0] }
  313.  
  314. sub proxy_authenticate  { (shift->_header('Proxy-Authenticate',  @_))[0] }
  315. sub proxy_authorization { (shift->_header('Proxy-Authorization', @_))[0] }
  316.  
  317. sub authorization_basic       { shift->_basic_auth("Authorization",       @_) }
  318. sub proxy_authorization_basic { shift->_basic_auth("Proxy-Authorization", @_) }
  319.  
  320. sub _basic_auth {
  321.     require MIME::Base64;
  322.     my($self, $h, $user, $passwd) = @_;
  323.     my($old) = $self->_header($h);
  324.     if (defined $user) {
  325.     Carp::croak("Basic authorization user name can't contain ':'")
  326.       if $user =~ /:/;
  327.     $passwd = '' unless defined $passwd;
  328.     $self->_header($h => 'Basic ' .
  329.                              MIME::Base64::encode("$user:$passwd", ''));
  330.     }
  331.     if (defined $old && $old =~ s/^\s*Basic\s+//) {
  332.     my $val = MIME::Base64::decode($old);
  333.     return $val unless wantarray;
  334.     return split(/:/, $val, 2);
  335.     }
  336.     return;
  337. }
  338.  
  339.  
  340. 1;
  341.  
  342. __END__
  343.  
  344. =head1 NAME
  345.  
  346. HTTP::Headers - Class encapsulating HTTP Message headers
  347.  
  348. =head1 SYNOPSIS
  349.  
  350.  require HTTP::Headers;
  351.  $h = HTTP::Headers->new;
  352.  
  353.  $h->header('Content-Type' => 'text/plain');  # set
  354.  $ct = $h->header('Content-Type');            # get
  355.  $h->remove_header('Content-Type');           # delete
  356.  
  357. =head1 DESCRIPTION
  358.  
  359. The C<HTTP::Headers> class encapsulates HTTP-style message headers.
  360. The headers consist of attribute-value pairs also called fields, which
  361. may be repeated, and which are printed in a particular order.
  362.  
  363. Instances of this class are usually created as member variables of the
  364. C<HTTP::Request> and C<HTTP::Response> classes, internal to the
  365. library.
  366.  
  367. The following methods are available:
  368.  
  369. =over 4
  370.  
  371. =item $h = HTTP::Headers->new
  372.  
  373. Constructs a new C<HTTP::Headers> object.  You might pass some initial
  374. attribute-value pairs as parameters to the constructor.  I<E.g.>:
  375.  
  376.  $h = HTTP::Headers->new(
  377.        Date         => 'Thu, 03 Feb 1994 00:00:00 GMT',
  378.        Content_Type => 'text/html; version=3.2',
  379.        Content_Base => 'http://www.perl.org/');
  380.  
  381. The constructor arguments are passed to the C<header> method which is
  382. described below.
  383.  
  384. =item $h->clone
  385.  
  386. Returns a copy of this C<HTTP::Headers> object.
  387.  
  388. =item $h->header( $field )
  389.  
  390. =item $h->header( $field => $value, ... )
  391.  
  392. Get or set the value of one or more header fields.  The header field name
  393. ($field) is not case sensitive.  To make the life easier for perl
  394. users who wants to avoid quoting before the => operator, you can use
  395. '_' as a replacement for '-' in header names (this behaviour can be
  396. suppressed by setting the $HTTP::Headers::TRANSLATE_UNDERSCORE
  397. variable to a FALSE value).
  398.  
  399. The header() method accepts multiple ($field => $value) pairs, which
  400. means that you can update several fields with a single invocation.
  401.  
  402. The $value argument may be a plain string or a reference to an array
  403. of strings for a multi-valued field. If the $value is undefined or not
  404. given, then that header field will remain unchanged.
  405.  
  406. The old value (or values) of the last of the header fields is returned.
  407. If no such field exists C<undef> will be returned.
  408.  
  409. A multi-valued field will be returned as separate values in list
  410. context and will be concatenated with ", " as separator in scalar
  411. context.  The HTTP spec (RFC 2616) promise that joining multiple
  412. values in this way will not change the semantic of a header field, but
  413. in practice there are cases like old-style Netscape cookies (see
  414. L<HTTP::Cookies>) where "," is used as part of the syntax of a single
  415. field value.
  416.  
  417. Examples:
  418.  
  419.  $header->header(MIME_Version => '1.0',
  420.          User_Agent   => 'My-Web-Client/0.01');
  421.  $header->header(Accept => "text/html, text/plain, image/*");
  422.  $header->header(Accept => [qw(text/html text/plain image/*)]);
  423.  @accepts = $header->header('Accept');  # get multiple values
  424.  $accepts = $header->header('Accept');  # get values as a single string
  425.  
  426. =item $h->push_header( $field => $value )
  427.  
  428. Add a new field value for the specified header field.  Previous values
  429. for the same field are retained.
  430.  
  431. As for the header() method, the field name ($field) is not case
  432. sensitive and '_' can be used as a replacement for '-'.
  433.  
  434. The $value argument may be a scalar or a reference to a list of
  435. scalars.
  436.  
  437.  $header->push_header(Accept => 'image/jpeg');
  438.  $header->push_header(Accept => [map "image/$_", qw(gif png tiff)]);
  439.  
  440. =item $h->init_header( $field => $value )
  441.  
  442. Set the specified header to the given value, but only if no previous
  443. value for that field is set.
  444.  
  445. The header field name ($field) is not case sensitive and '_'
  446. can be used as a replacement for '-'.
  447.  
  448. The $value argument may be a scalar or a reference to a list of
  449. scalars.
  450.  
  451. =item $h->remove_header( $field, ... )
  452.  
  453. This function removes the header fields with the specified names.
  454.  
  455. The header field names ($field) are not case sensitive and '_'
  456. can be used as a replacement for '-'.
  457.  
  458. The return value is the values of the fields removed.  In scalar
  459. context the number of fields removed is returned.
  460.  
  461. Note that if you pass in multiple field names then it is generally not
  462. possible to tell which of the returned values belonged to which field.
  463.  
  464. =item $h->remove_content_headers
  465.  
  466. This will remove all the header fields used to describe the content of
  467. a message.  All header field names prefixed with C<Content-> falls
  468. into this category, as well as C<Allow>, C<Expires> and
  469. C<Last-Modified>.  RFC 2616 denote these fields as I<Entity Header
  470. Fields>.
  471.  
  472. The return value is a new C<HTTP::Headers> object that contains the
  473. removed headers only.
  474.  
  475. =item $h->clear
  476.  
  477. This will remove all header fields.
  478.  
  479. =item $h->header_field_names
  480.  
  481. Returns the list of distinct names for the fields present in the
  482. header.  The field names have case as suggested by HTTP spec, and the
  483. names are returned in the recommended "Good Practice" order.
  484.  
  485. In scalar context return the number of distinct field names.
  486.  
  487. =item $h->scan( \&process_header_field )
  488.  
  489. Apply a subroutine to each header field in turn.  The callback routine
  490. is called with two parameters; the name of the field and a single
  491. value (a string).  If a header field is multi-valued, then the
  492. routine is called once for each value.  The field name passed to the
  493. callback routine has case as suggested by HTTP spec, and the headers
  494. will be visited in the recommended "Good Practice" order.
  495.  
  496. Any return values of the callback routine are ignored.  The loop can
  497. be broken by raising an exception (C<die>), but the caller of scan()
  498. would have to trap the exception itself.
  499.  
  500. =item $h->as_string
  501.  
  502. =item $h->as_string( $eol )
  503.  
  504. Return the header fields as a formatted MIME header.  Since it
  505. internally uses the C<scan> method to build the string, the result
  506. will use case as suggested by HTTP spec, and it will follow
  507. recommended "Good Practice" of ordering the header fields.  Long header
  508. values are not folded.
  509.  
  510. The optional $eol parameter specifies the line ending sequence to
  511. use.  The default is "\n".  Embedded "\n" characters in header field
  512. values will be substituted with this line ending sequence.
  513.  
  514. =back
  515.  
  516. =head1 CONVENIENCE METHODS
  517.  
  518. The most frequently used headers can also be accessed through the
  519. following convenience methods.  These methods can both be used to read
  520. and to set the value of a header.  The header value is set if you pass
  521. an argument to the method.  The old header value is always returned.
  522. If the given header did not exist then C<undef> is returned.
  523.  
  524. Methods that deal with dates/times always convert their value to system
  525. time (seconds since Jan 1, 1970) and they also expect this kind of
  526. value when the header value is set.
  527.  
  528. =over 4
  529.  
  530. =item $h->date
  531.  
  532. This header represents the date and time at which the message was
  533. originated. I<E.g.>:
  534.  
  535.   $h->date(time);  # set current date
  536.  
  537. =item $h->expires
  538.  
  539. This header gives the date and time after which the entity should be
  540. considered stale.
  541.  
  542. =item $h->if_modified_since
  543.  
  544. =item $h->if_unmodified_since
  545.  
  546. These header fields are used to make a request conditional.  If the requested
  547. resource has (or has not) been modified since the time specified in this field,
  548. then the server will return a C<304 Not Modified> response instead of
  549. the document itself.
  550.  
  551. =item $h->last_modified
  552.  
  553. This header indicates the date and time at which the resource was last
  554. modified. I<E.g.>:
  555.  
  556.   # check if document is more than 1 hour old
  557.   if (my $last_mod = $h->last_modified) {
  558.       if ($last_mod < time - 60*60) {
  559.       ...
  560.       }
  561.   }
  562.  
  563. =item $h->content_type
  564.  
  565. The Content-Type header field indicates the media type of the message
  566. content. I<E.g.>:
  567.  
  568.   $h->content_type('text/html');
  569.  
  570. The value returned will be converted to lower case, and potential
  571. parameters will be chopped off and returned as a separate value if in
  572. an array context.  If there is no such header field, then the empty
  573. string is returned.  This makes it safe to do the following:
  574.  
  575.   if ($h->content_type eq 'text/html') {
  576.      # we enter this place even if the real header value happens to
  577.      # be 'TEXT/HTML; version=3.0'
  578.      ...
  579.   }
  580.  
  581. =item $h->content_encoding
  582.  
  583. The Content-Encoding header field is used as a modifier to the
  584. media type.  When present, its value indicates what additional
  585. encoding mechanism has been applied to the resource.
  586.  
  587. =item $h->content_length
  588.  
  589. A decimal number indicating the size in bytes of the message content.
  590.  
  591. =item $h->content_language
  592.  
  593. The natural language(s) of the intended audience for the message
  594. content.  The value is one or more language tags as defined by RFC
  595. 1766.  Eg. "no" for some kind of Norwegian and "en-US" for English the
  596. way it is written in the US.
  597.  
  598. =item $h->title
  599.  
  600. The title of the document.  In libwww-perl this header will be
  601. initialized automatically from the E<lt>TITLE>...E<lt>/TITLE> element
  602. of HTML documents.  I<This header is no longer part of the HTTP
  603. standard.>
  604.  
  605. =item $h->user_agent
  606.  
  607. This header field is used in request messages and contains information
  608. about the user agent originating the request.  I<E.g.>:
  609.  
  610.   $h->user_agent('Mozilla/1.2');
  611.  
  612. =item $h->server
  613.  
  614. The server header field contains information about the software being
  615. used by the originating server program handling the request.
  616.  
  617. =item $h->from
  618.  
  619. This header should contain an Internet e-mail address for the human
  620. user who controls the requesting user agent.  The address should be
  621. machine-usable, as defined by RFC822.  E.g.:
  622.  
  623.   $h->from('King Kong <king@kong.com>');
  624.  
  625. I<This header is no longer part of the HTTP standard.>
  626.  
  627. =item $h->referer
  628.  
  629. Used to specify the address (URI) of the document from which the
  630. requested resource address was obtained.
  631.  
  632. The "Free On-line Dictionary of Computing" as this to say about the
  633. word I<referer>:
  634.  
  635.      <World-Wide Web> A misspelling of "referrer" which
  636.      somehow made it into the {HTTP} standard.  A given {web
  637.      page}'s referer (sic) is the {URL} of whatever web page
  638.      contains the link that the user followed to the current
  639.      page.  Most browsers pass this information as part of a
  640.      request.
  641.  
  642.      (1998-10-19)
  643.  
  644. By popular demand C<referrer> exists as an alias for this method so you
  645. can avoid this misspelling in your programs and still send the right
  646. thing on the wire.
  647.  
  648. When setting the referrer, this method removes the fragment from the
  649. given URI if it is present, as mandated by RFC2616.  Note that
  650. the removal does I<not> happen automatically if using the header(),
  651. push_header() or init_header() methods to set the referrer.
  652.  
  653. =item $h->www_authenticate
  654.  
  655. This header must be included as part of a C<401 Unauthorized> response.
  656. The field value consist of a challenge that indicates the
  657. authentication scheme and parameters applicable to the requested URI.
  658.  
  659. =item $h->proxy_authenticate
  660.  
  661. This header must be included in a C<407 Proxy Authentication Required>
  662. response.
  663.  
  664. =item $h->authorization
  665.  
  666. =item $h->proxy_authorization
  667.  
  668. A user agent that wishes to authenticate itself with a server or a
  669. proxy, may do so by including these headers.
  670.  
  671. =item $h->authorization_basic
  672.  
  673. This method is used to get or set an authorization header that use the
  674. "Basic Authentication Scheme".  In array context it will return two
  675. values; the user name and the password.  In scalar context it will
  676. return I<"uname:password"> as a single string value.
  677.  
  678. When used to set the header value, it expects two arguments.  I<E.g.>:
  679.  
  680.   $h->authorization_basic($uname, $password);
  681.  
  682. The method will croak if the $uname contains a colon ':'.
  683.  
  684. =item $h->proxy_authorization_basic
  685.  
  686. Same as authorization_basic() but will set the "Proxy-Authorization"
  687. header instead.
  688.  
  689. =back
  690.  
  691. =head1 BUGS
  692.  
  693. In the argument list to the constructor or header() method, the same
  694. field name should not occur multiple times.  The result of doing so,
  695. it that only the last of these fields will be present in the header
  696. after the call.  All values ought to be kept.
  697.  
  698. Passing a value of C<undef> to header() or any of the convenience
  699. methods, does not delete that field.  It ought to do that.
  700.  
  701. =head1 COPYRIGHT
  702.  
  703. Copyright 1995-2004 Gisle Aas.
  704.  
  705. This library is free software; you can redistribute it and/or
  706. modify it under the same terms as Perl itself.
  707.  
  708.