ActiveState!

ActivePerl Documentation
Table of Contents

(Usage Statistics)
(about this ver)


* Getting Started
    * Welcome To ActivePerl
    * Release Notes
    * Readme
    * ActivePerl Change Log
* Install Notes
    * Linux
    * Solaris
    * Windows
* ActivePerl Components
    * Overview
    * PPM
    * Windows Specifics
       * OLE Browser
       * PerlScript
       * Perl for ISAPI
       * PerlEZ
* ActivePerl FAQ
    * Introduction
    * Availability & Install
    * Using PPM
    * Docs & Support
    * Windows Specifics
       * Perl for ISAPI
       * Windows 9X/NT/2000
       * Quirks
       * Web Server Config
       * Web programming
       * Programming
       * Modules & Samples
       * Embedding & Extending
       * Using OLE with Perl
* Windows Scripting
    * Active Server Pages
    * Windows Script Host
    * Windows Script Components

Core Perl Documentation


* perl
* perlfaq
* perltoc
* perlbook

* perlsyn
* perldata
* perlop
* perlreftut
* perldsc
* perllol

* perllexwarn
* perldebug

* perlrun
* perlfunc
* perlopentut
* perlvar
* perlsub
* perlmod
* perlpod

* perlstyle
* perlmodlib
* perlmodinstall
* perltrap
* perlport
* perlsec

* perlref
* perlre
* perlform
* perllocale
* perlunicode

* perlboot
* perltoot
* perltootc
* perlobj
* perlbot
* perltie

* perlipc
* perlnumber
* perlfork
* perlthrtut

* perldiag
* perlfaq1
* perlfaq2
* perlfaq3
* perlfaq4
* perlfaq5
* perlfaq6
* perlfaq7
* perlfaq8
* perlfaq9

* perlcompile

* perlembed
* perlxstut
* perlxs
* perlguts
* perlcall
* perlfilter
* perldbmfilter
* perlapi
* perlintern
* perlapio
* perltodo
* perlhack

* perlhist
* perldelta
* perl5005delta
* perl5004delta

* perlamiga
* perlcygwin
* perldos
* perlhpux
* perlmachten
* perlos2
* perlos390
* perlvms
* perlwin32

Pragmas


* attributes
* attrs
* autouse
* base
* blib
* bytes
* charnames
* constant
* diagnostics
* fields
* filetest
* integer
* less
* lib
* locale
* lwpcook
* open
* ops
* overload
* perllocal
* re
* sigtrap
* strict
* subs
* utf8
* vars
* warnings

Libraries


* ActivePerl
    * DocTools
        * TOC
            * RDF
* AnyDBM_File
* Archive
    * Tar
* AutoLoader
* AutoSplit
* B
    * Asmdata
    * Assembler
    * Bblock
    * Bytecode
    * C
    * CC
    * Debug
    * Deparse
    * Disassembler
    * Lint
    * Showlex
    * Stackobj
    * Terse
    * Xref
* Benchmark
* Bundle
    * LWP
* ByteLoader
* Carp
    * Heavy
* CGI
    * Apache
    * Carp
    * Cookie
    * Fast
    * Pretty
    * Push
    * Switch
* Class
    * Struct
* Compress
    * Zlib
* Config
* CPAN
    * FirstTime
    * Nox
* Cwd
* Data
    * Dumper
* DB
* Devel
    * DProf
    * Peek
    * SelfStubber
* Digest
    * HMAC
    * HMAC_MD5
    * HMAC_SHA1
    * MD2
    * MD5
    * SHA1
* DirHandle
* Dumpvalue
* DynaLoader
* English
* Env
* Errno
* Exporter
    * Heavy
* ExtUtils
    * Command
    * Embed
    * Install
    * Installed
    * Liblist
    * MakeMaker
    * Manifest
    * Miniperl
    * Mkbootstrap
    * Mksymlists
    * MM_Cygwin
    * MM_OS2
    * MM_Unix
    * MM_VMS
    * MM_Win32
    * Packlist
    * testlib
* Fatal
* Fcntl
* File
    * Basename
    * CheckTree
    * Compare
    * Copy
    * CounterFile
    * DosGlob
    * Find
    * Glob
    * Listing
    * Path
    * Spec
        * Functions
        * Mac
        * OS2
        * Unix
        * VMS
        * Win32
    * stat
* FileCache
* FileHandle
* FindBin
* Font
    * AFM
* Getopt
    * Long
    * Std
* HTML
    * AsSubs
    * Element
    * Entities
    * Filter
    * Form
    * FormatPS
    * Formatter
    * FormatText
    * HeadParser
    * LinkExtor
    * Parse
    * Parser
    * TokeParser
    * TreeBuilder
* HTTP
    * Cookies
    * Daemon
    * Date
    * Headers
        * Util
    * Message
    * Negotiate
    * Request
        * Common
    * Response
    * Status
* I18N
    * Collate
* IO
    * Dir
    * File
    * Handle
    * Pipe
    * Poll
    * Seekable
    * Select
    * Socket
        * INET
        * UNIX
* IPC
    * Msg
    * Open2
    * Open3
    * Semaphore
    * SysV
* LWP
    * Debug
    * MediaTypes
    * MemberMixin
    * Protocol
    * RobotUA
    * Simple
    * UserAgent
* Math
    * BigFloat
    * BigInt
    * Complex
    * Trig
* MD5
* MIME
    * Base64
    * QuotedPrint
* NDBM_File
* Net
    * Cmd
    * Config
    * Domain
    * DummyInetd
    * FTP
    * hostent
    * libnetFAQ
    * netent
    * Netrc
    * NNTP
    * PH
    * Ping
    * POP3
    * protoent
    * servent
    * SMTP
    * SNPP
    * Time
* O
* ODBM_File
* Opcode
* Pod
    * Checker
    * Find
    * Html
    * InputObjects
    * Man
    * Parser
    * ParseUtils
    * Plainer
    * Select
    * Text
        * Color
        * Termcap
    * Usage
* POSIX
* PPM
    * SOAPClient
    * SOAPServer
* Safe
* SDBM_File
* Search
    * Dict
* SelectSaver
* SelfLoader
* SHA
* Shell
* SOAP
    * Defs
    * Envelope
    * EnvelopeMaker
    * GenericHashSerializer
    * GenericInputStream
    * GenericScalarSerializer
    * Lite
    * OutputStream
    * Packager
    * Parser
    * Transport
        * HTTP
            * Apache
            * CGI
            * Client
            * Server
        * LOCAL
        * MAILTO
        * POP3
        * TCP
    * TypeMapper
* Socket
* Symbol
* Sys
    * Hostname
    * Syslog
* Term
    * ANSIColor
    * Cap
    * Complete
    * ReadLine
* Test
    * Harness
* Text
    * Abbrev
    * ParseWords
    * Soundex
    * Tabs
    * Wrap
* Thread
    * Queue
    * Semaphore
    * Signal
    * Specific
* Tie
    * Array
    * Handle
    * Hash
    * RefHash
    * Scalar
    * SubstrHash
* Time
    * gmtime
    * Local
    * localtime
    * tm
* UDDI
    * Lite
* UNIVERSAL
* URI
    * data
    * Escape
    * file
    * Heuristic
    * ldap
    * URL
    * WithBase
* User
    * grent
    * pwent
* Win32
    * AuthenticateUser
    * ChangeNotify
    * Clipboard
    * Console
    * Event
    * EventLog
    * File
    * FileSecurity
    * Internet
    * IPC
    * Mutex
    * NetAdmin
    * NetResource
    * ODBC
    * OLE
        * Const
        * Enum
        * NEWS
        * NLS
        * TPJ
        * Variant
    * PerfLib
    * Pipe
    * Process
    * Registry
    * Semaphore
    * Service
    * Sound
    * TieRegistry
* Win32API
    * File
    * Net
    * Registry
* WWW
    * RobotRules
        * AnyDBM_File
* XML
    * Element
    * Parser
        * Expat
    * PPD
    * PPMConfig
    * ValidatingElement
* XSLoader

 HTTP::Headers - Class encapsulating HTTP Message headers


NAME

HTTP::Headers - Class encapsulating HTTP Message headers


SUPPORTED PLATFORMS

  • Linux
  • Solaris
  • Windows

SYNOPSIS

 require HTTP::Headers;
 $h = new HTTP::Headers;


DESCRIPTION

The HTTP::Headers class encapsulates HTTP-style message headers. The headers consist of attribute-value pairs, which may be repeated, and which are printed in a particular order.

Instances of this class are usually created as member variables of the HTTP::Request and HTTP::Response classes, internal to the library.

The following methods are available:

$h = new HTTP::Headers
Constructs a new HTTP::Headers object. You might pass some initial attribute-value pairs as parameters to the constructor. E.g.:
 $h = new HTTP::Headers
     Date         => 'Thu, 03 Feb 1994 00:00:00 GMT',
     Content_Type => 'text/html; version=3.2',
     Content_Base => 'http://www.sn.no/';

$h->header($field [=> $value],...)
Get or set the value of a header. The header field name 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 synonym for '-' in header names (this behaviour can be suppressed by setting $HTTP::Headers::TRANSLATE_UNDERSCORE to a FALSE value).

The header() method accepts multiple ($field => $value) pairs, so you can update several fields with a single invocation.

The optional $value argument may be a scalar or a reference to a list of scalars. If the $value argument is undefined or not given, then the header is not modified.

The old value of the last of the $field values is returned. Multi-valued fields will be concatenated with ``,'' as separator in scalar context.

 $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');

$h->scan(\&doit)
Apply a subroutine to each header in turn. The callback routine is called with two parameters; the name of the field and a single value. If the header has more than one value, then the routine is called once for each value. The field name passed to the callback routine has case as suggested by HTTP Spec, and the headers will be visited in the recommended ``Good Practice'' order.

$h->as_string([$endl])
Return the header fields as a formatted MIME header. Since it internally uses the scan() method to build the string, the result will use case as suggested by HTTP Spec, and it will follow recommended ``Good Practice'' of ordering the header fieds. Long header values are not folded.

The optional parameter specifies the line ending sequence to use. The default is "\n". Embedded ``\n'' characters in the header will be substitued with this line ending sequence.

$h->push_header($field, $val)
Add a new field value of the specified header. The header field name is not case sensitive. The field need not already have a value. Previous values for the same field are retained. The argument may be a scalar or a reference to a list of scalars.
 $header->push_header(Accept => 'image/jpeg');

$h->remove_header($field,...)
This function removes the headers with the specified names.

$h->clone
Returns a copy of this HTTP::Headers object.


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.

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.

$h->date
This header represents the date and time at which the message was originated. E.g.:
  $h->date(time);  # set current date

$h->expires
This header gives the date and time after which the entity should be considered stale.

$h->if_modified_since
$h->if_unmodified_since
This header is used to make a request conditional. If the requested resource has (not) been modified since the time specified in this field, then the server will return a "304 Not Modified" response instead of the document itself.

$h->last_modified
This header indicates the date and time at which the resource was last modified. E.g.:
  # check if document is more than 1 hour old
  if ($h->last_modified < time - 60*60) {
        ...
  }

$h->content_type
The Content-Type header field indicates the media type of the message content. E.g.:
  $h->content_type('text/html');

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. This makes it safe to do the following:

  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'
     ...
  }

$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.

$h->content_length
A decimal number indicating the size in bytes of the message content.

$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 RFC 1766. Eg. ``no'' for Norwegian and ``en-US'' for US-English.

$h->title
The title of the document. In libwww-perl this header will be initialized automatically from the <TITLE>...</TITLE> element of HTML documents. This header is no longer part of the HTTP standard.

$h->user_agent
This header field is used in request messages and contains information about the user agent originating the request. E.g.:
  $h->user_agent('Mozilla/1.2');

$h->server
The server header field contains information about the software being used by the originating server program handling the request.

$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 RFC822. E.g.:
  $h->from('Gisle Aas <aas@sn.no>');

$h->referer
Used to specify the address (URI) of the document from which the requested resouce address was obtained.

$h->www_authenticate
This header must be included as part of a ``401 Unauthorized'' response. The field value consist of a challenge that indicates the authentication scheme and parameters applicable to the requested URI.

$h->proxy_authenticate
This header must be included in a ``407 Proxy Authentication Required'' response.

$h->authorization
$h->proxy_authorization
A user agent that wishes to authenticate itself with a server or a proxy, may do so by including these headers.

$h->authorization_basic
This method is used to get or set an authorization header that use the ``Basic Authentication Scheme''. In array context it will return two values; the user name and the password. In scalar context it will return ``uname:password'' as a single string value.

When used to set the header value, it expects two arguments. E.g.:

  $h->authorization_basic($uname, $password);

The method will croak if the $uname contains a colon ':'.

$h->proxy_authorization_basic
Same as authorization_basic() but will set the ``Proxy-Authorization'' header instead.


COPYRIGHT

Copyright 1995-1998 Gisle Aas.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

 HTTP::Headers - Class encapsulating HTTP Message headers