.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.14 .\" .\" Standard preamble: .\" ======================================================================== .de Sh \" Subsection heading .br .if t .Sp .ne 5 .PP \fB\\$1\fR .PP .. .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. | will give a .\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to .\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C' .\" expand to `' in nroff, nothing in troff, for use with C<>. .tr \(*W-|\(bv\*(Tr .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' 'br\} .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .\" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .hy 0 .if n .na .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "HTTP::Headers 3" .TH HTTP::Headers 3 "2004-04-06" "perl v5.8.4" "User Contributed Perl Documentation" .SH "NAME" HTTP::Headers \- Class encapsulating HTTP Message headers .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& require HTTP::Headers; \& $h = HTTP::Headers->new; .Ve .PP .Vb 3 \& $h->header('Content-Type' => 'text/plain'); # set \& $ct = $h->header('Content-Type'); # get \& $h->remove_header('Content-Type'); # delete .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" The \f(CW\*(C`HTTP::Headers\*(C'\fR class encapsulates HTTP-style message headers. The headers consist of attribute-value pairs also called fields, which may be repeated, and which are printed in a particular order. The field names are cases insensitive. .PP Instances of this class are usually created as member variables of the \&\f(CW\*(C`HTTP::Request\*(C'\fR and \f(CW\*(C`HTTP::Response\*(C'\fR classes, internal to the library. .PP The following methods are available: .IP "$h = HTTP::Headers\->new" 4 .IX Item "$h = HTTP::Headers->new" Constructs a new \f(CW\*(C`HTTP::Headers\*(C'\fR object. You might pass some initial attribute-value pairs as parameters to the constructor. \fIE.g.\fR: .Sp .Vb 4 \& $h = HTTP::Headers->new( \& Date => 'Thu, 03 Feb 1994 00:00:00 GMT', \& Content_Type => 'text/html; version=3.2', \& Content_Base => 'http://www.perl.org/'); .Ve .Sp The constructor arguments are passed to the \f(CW\*(C`header\*(C'\fR method which is described below. .IP "$h\->clone" 4 .IX Item "$h->clone" Returns a copy of this \f(CW\*(C`HTTP::Headers\*(C'\fR object. .ie n .IP "$h\->header( $field )" 4 .el .IP "$h\->header( \f(CW$field\fR )" 4 .IX Item "$h->header( $field )" .PD 0 .ie n .IP "$h\->header( $field\fR => \f(CW$value, ... )" 4 .el .IP "$h\->header( \f(CW$field\fR => \f(CW$value\fR, ... )" 4 .IX Item "$h->header( $field => $value, ... )" .PD Get or set the value of one or more header fields. The header field name ($field) is not case sensitive. To make the life easier for perl users who wants to avoid quoting before the => operator, you can use \&'_' as a replacement for '\-' in header names. .Sp The \fIheader()\fR method accepts multiple ($field => \f(CW$value\fR) pairs, which means that you can update several fields with a single invocation. .Sp The \f(CW$value\fR argument may be a plain string or a reference to an array of strings for a multi-valued field. If the \f(CW$value\fR is provided as \&\f(CW\*(C`undef\*(C'\fR then the field is removed. If the \f(CW$value\fR is not given, then that header field will remain unchanged. .Sp The old value (or values) of the last of the header fields is returned. If no such field exists \f(CW\*(C`undef\*(C'\fR will be returned. .Sp A multi-valued field will be returned as separate values in list context and will be concatenated with \*(L", \*(R" as separator in scalar context. The \s-1HTTP\s0 spec (\s-1RFC\s0 2616) promise that joining multiple values in this way will not change the semantic of a header field, but in practice there are cases like old-style Netscape cookies (see HTTP::Cookies) where \*(L",\*(R" is used as part of the syntax of a single field value. .Sp Examples: .Sp .Vb 6 \& $header->header(MIME_Version => '1.0', \& User_Agent => 'My-Web-Client/0.01'); \& $header->header(Accept => "text/html, text/plain, image/*"); \& $header->header(Accept => [qw(text/html text/plain image/*)]); \& @accepts = $header->header('Accept'); # get multiple values \& $accepts = $header->header('Accept'); # get values as a single string .Ve .ie n .IP "$h\->push_header( $field\fR => \f(CW$value )" 4 .el .IP "$h\->push_header( \f(CW$field\fR => \f(CW$value\fR )" 4 .IX Item "$h->push_header( $field => $value )" Add a new field value for the specified header field. Previous values for the same field are retained. .Sp As for the \fIheader()\fR method, the field name ($field) is not case sensitive and '_' can be used as a replacement for '\-'. .Sp The \f(CW$value\fR argument may be a scalar or a reference to a list of scalars. .Sp .Vb 2 \& $header->push_header(Accept => 'image/jpeg'); \& $header->push_header(Accept => [map "image/$_", qw(gif png tiff)]); .Ve .ie n .IP "$h\->init_header( $field\fR => \f(CW$value )" 4 .el .IP "$h\->init_header( \f(CW$field\fR => \f(CW$value\fR )" 4 .IX Item "$h->init_header( $field => $value )" Set the specified header to the given value, but only if no previous value for that field is set. .Sp The header field name ($field) is not case sensitive and '_' can be used as a replacement for '\-'. .Sp The \f(CW$value\fR argument may be a scalar or a reference to a list of scalars. .ie n .IP "$h\->remove_header( $field, ... )" 4 .el .IP "$h\->remove_header( \f(CW$field\fR, ... )" 4 .IX Item "$h->remove_header( $field, ... )" This function removes the header fields with the specified names. .Sp The header field names ($field) are not case sensitive and '_' can be used as a replacement for '\-'. .Sp The return value is the values of the fields removed. In scalar context the number of fields removed is returned. .Sp Note that if you pass in multiple field names then it is generally not possible to tell which of the returned values belonged to which field. .IP "$h\->remove_content_headers" 4 .IX Item "$h->remove_content_headers" This will remove all the header fields used to describe the content of a message. All header field names prefixed with \f(CW\*(C`Content\-\*(C'\fR falls into this category, as well as \f(CW\*(C`Allow\*(C'\fR, \f(CW\*(C`Expires\*(C'\fR and \&\f(CW\*(C`Last\-Modified\*(C'\fR. \s-1RFC\s0 2616 denote these fields as \fIEntity Header Fields\fR. .Sp The return value is a new \f(CW\*(C`HTTP::Headers\*(C'\fR object that contains the removed headers only. .IP "$h\->clear" 4 .IX Item "$h->clear" This will remove all header fields. .IP "$h\->header_field_names" 4 .IX Item "$h->header_field_names" Returns the list of distinct names for the fields present in the header. The field names have case as suggested by \s-1HTTP\s0 spec, and the names are returned in the recommended \*(L"Good Practice\*(R" order. .Sp In scalar context return the number of distinct field names. .IP "$h\->scan( \e&process_header_field )" 4 .IX Item "$h->scan( &process_header_field )" Apply a subroutine to each header field in turn. The callback routine is called with two parameters; the name of the field and a single value (a string). If a header field is multi\-valued, then the routine is called once for each value. The field name passed to the callback routine has case as suggested by \s-1HTTP\s0 spec, and the headers will be visited in the recommended \*(L"Good Practice\*(R" order. .Sp Any return values of the callback routine are ignored. The loop can be broken by raising an exception (\f(CW\*(C`die\*(C'\fR), but the caller of \fIscan()\fR would have to trap the exception itself. .IP "$h\->as_string" 4 .IX Item "$h->as_string" .PD 0 .ie n .IP "$h\->as_string( $eol )" 4 .el .IP "$h\->as_string( \f(CW$eol\fR )" 4 .IX Item "$h->as_string( $eol )" .PD Return the header fields as a formatted \s-1MIME\s0 header. Since it internally uses the \f(CW\*(C`scan\*(C'\fR method to build the string, the result will use case as suggested by \s-1HTTP\s0 spec, and it will follow recommended \*(L"Good Practice\*(R" of ordering the header fields. Long header values are not folded. .Sp The optional \f(CW$eol\fR parameter specifies the line ending sequence to use. The default is \*(L"\en\*(R". Embedded \*(L"\en\*(R" characters in header field values will be substituted with this line ending sequence. .SH "CONVENIENCE METHODS" .IX Header "CONVENIENCE METHODS" The most frequently used headers can also be accessed through the following convenience methods. These methods can both be used to read and to set the value of a header. The header value is set if you pass an argument to the method. The old header value is always returned. If the given header did not exist then \f(CW\*(C`undef\*(C'\fR is returned. .PP Methods that deal with dates/times always convert their value to system time (seconds since Jan 1, 1970) and they also expect this kind of value when the header value is set. .IP "$h\->date" 4 .IX Item "$h->date" This header represents the date and time at which the message was originated. \fIE.g.\fR: .Sp .Vb 1 \& $h->date(time); # set current date .Ve .IP "$h\->expires" 4 .IX Item "$h->expires" This header gives the date and time after which the entity should be considered stale. .IP "$h\->if_modified_since" 4 .IX Item "$h->if_modified_since" .PD 0 .IP "$h\->if_unmodified_since" 4 .IX Item "$h->if_unmodified_since" .PD These header fields are used to make a request conditional. If the requested resource has (or has not) been modified since the time specified in this field, then the server will return a \f(CW\*(C`304 Not Modified\*(C'\fR response instead of the document itself. .IP "$h\->last_modified" 4 .IX Item "$h->last_modified" This header indicates the date and time at which the resource was last modified. \fIE.g.\fR: .Sp .Vb 6 \& # check if document is more than 1 hour old \& if (my $last_mod = $h->last_modified) { \& if ($last_mod < time - 60*60) { \& ... \& } \& } .Ve .IP "$h\->content_type" 4 .IX Item "$h->content_type" The Content-Type header field indicates the media type of the message content. \fIE.g.\fR: .Sp .Vb 1 \& $h->content_type('text/html'); .Ve .Sp The value returned will be converted to lower case, and potential parameters will be chopped off and returned as a separate value if in an array context. If there is no such header field, then the empty string is returned. This makes it safe to do the following: .Sp .Vb 5 \& if ($h->content_type eq 'text/html') { \& # we enter this place even if the real header value happens to \& # be 'TEXT/HTML; version=3.0' \& ... \& } .Ve .IP "$h\->content_encoding" 4 .IX Item "$h->content_encoding" The Content-Encoding header field is used as a modifier to the media type. When present, its value indicates what additional encoding mechanism has been applied to the resource. .IP "$h\->content_length" 4 .IX Item "$h->content_length" A decimal number indicating the size in bytes of the message content. .IP "$h\->content_language" 4 .IX Item "$h->content_language" The natural language(s) of the intended audience for the message content. The value is one or more language tags as defined by \s-1RFC\s0 1766. Eg. \*(L"no\*(R" for some kind of Norwegian and \*(L"en\-US\*(R" for English the way it is written in the \s-1US\s0. .IP "$h\->title" 4 .IX Item "$h->title" The title of the document. In libwww-perl this header will be initialized automatically from the <\s-1TITLE\s0>... element of \s-1HTML\s0 documents. \fIThis header is no longer part of the \s-1HTTP\s0 standard.\fR .IP "$h\->user_agent" 4 .IX Item "$h->user_agent" This header field is used in request messages and contains information about the user agent originating the request. \fIE.g.\fR: .Sp .Vb 1 \& $h->user_agent('Mozilla/1.2'); .Ve .IP "$h\->server" 4 .IX Item "$h->server" The server header field contains information about the software being used by the originating server program handling the request. .IP "$h\->from" 4 .IX Item "$h->from" This header should contain an Internet e\-mail address for the human user who controls the requesting user agent. The address should be machine\-usable, as defined by \s-1RFC822\s0. E.g.: .Sp .Vb 1 \& $h->from('King Kong '); .Ve .Sp \&\fIThis header is no longer part of the \s-1HTTP\s0 standard.\fR .IP "$h\->referer" 4 .IX Item "$h->referer" Used to specify the address (\s-1URI\s0) of the document from which the requested resource address was obtained. .Sp The \*(L"Free On-line Dictionary of Computing\*(R" as this to say about the word \fIreferer\fR: .Sp .Vb 6 \& A misspelling of "referrer" which \& somehow made it into the {HTTP} standard. A given {web \& page}'s referer (sic) is the {URL} of whatever web page \& contains the link that the user followed to the current \& page. Most browsers pass this information as part of a \& request. .Ve .Sp .Vb 1 \& (1998-10-19) .Ve .Sp By popular demand \f(CW\*(C`referrer\*(C'\fR exists as an alias for this method so you can avoid this misspelling in your programs and still send the right thing on the wire. .Sp When setting the referrer, this method removes the fragment from the given \s-1URI\s0 if it is present, as mandated by \s-1RFC2616\s0. Note that the removal does \fInot\fR happen automatically if using the \fIheader()\fR, \&\fIpush_header()\fR or \fIinit_header()\fR methods to set the referrer. .IP "$h\->www_authenticate" 4 .IX Item "$h->www_authenticate" This header must be included as part of a \f(CW\*(C`401 Unauthorized\*(C'\fR response. The field value consist of a challenge that indicates the authentication scheme and parameters applicable to the requested \s-1URI\s0. .IP "$h\->proxy_authenticate" 4 .IX Item "$h->proxy_authenticate" This header must be included in a \f(CW\*(C`407 Proxy Authentication Required\*(C'\fR response. .IP "$h\->authorization" 4 .IX Item "$h->authorization" .PD 0 .IP "$h\->proxy_authorization" 4 .IX Item "$h->proxy_authorization" .PD A user agent that wishes to authenticate itself with a server or a proxy, may do so by including these headers. .IP "$h\->authorization_basic" 4 .IX Item "$h->authorization_basic" This method is used to get or set an authorization header that use the \&\*(L"Basic Authentication Scheme\*(R". In array context it will return two values; the user name and the password. In scalar context it will return \fI\*(L"uname:password\*(R"\fR as a single string value. .Sp When used to set the header value, it expects two arguments. \fIE.g.\fR: .Sp .Vb 1 \& $h->authorization_basic($uname, $password); .Ve .Sp The method will croak if the \f(CW$uname\fR contains a colon ':'. .IP "$h\->proxy_authorization_basic" 4 .IX Item "$h->proxy_authorization_basic" Same as \fIauthorization_basic()\fR but will set the \*(L"Proxy\-Authorization\*(R" header instead. .SH "NON-CANONICALIZED FIELD NAMES" .IX Header "NON-CANONICALIZED FIELD NAMES" The header field name spelling is normally canonicalized including the \&'_' to '\-' translation. There are some application where this is not appropriate. Prefixing field names with ':' allow you to force a specific spelling. For example if you really want a header field name to show up as \f(CW\*(C`foo_bar\*(C'\fR instead of \*(L"Foo\-Bar\*(R", you might set it like this: .PP .Vb 1 \& $h->header(":foo_bar" => 1); .Ve .PP These field names are returned with the ':' intact for \&\f(CW$h\fR\->header_field_names and the \f(CW$h\fR\->scan callback, but the colons do not show in \f(CW$h\fR\->as_string. .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright 1995\-2005 Gisle Aas. .PP This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.