SYNOPSIS

 use base 'HTTP::Message';

DESCRIPTION

An \*(C`HTTP::Message\*(C' object contains some headers and a content body. The following methods are available: This constructs a new message object. Normally you would want construct \*(C`HTTP::Request\*(C' or \*(C`HTTP::Response\*(C' objects instead. The optional $header argument should be a reference to an \*(C`HTTP::Headers\*(C' object or a plain array reference of key/value pairs. If an \*(C`HTTP::Headers\*(C' object is provided then a copy of it will be embedded into the constructed message, i.e. it will not be owned and can be modified afterwards without affecting the message. The optional $content argument should be a string of bytes. This constructs a new message object by parsing the given string. Returns the embedded \*(C`HTTP::Headers\*(C' object. Call the as_string() method for the headers in the message. This will be the same as $mess->headers->as_string but it will make your program a whole character shorter :-) The content() method sets the raw content if an argument is given. If no argument is given the content is not touched. In either case the original raw content is returned. Note that the content should be a string of bytes. Strings in perl can contain characters outside the range of a byte. The \*(C`Encode\*(C' module can be used to turn such strings into a string of bytes. The add_content() methods appends more data bytes to the end of the current content buffer. The add_content_utf8() method appends the \s-1UTF-8\s0 bytes representing the string to the end of the current content buffer. The content_ref() method will return a reference to content buffer string. It can be more efficient to access the content this way if the content is huge, and it can even be used for direct manipulation of the content, for instance: ${$res->content_ref} =~ s/\bfoo\b/bar/g; This example would modify the content buffer in-place. If an argument is passed it will setup the content to reference some external source. The content() and add_content() methods will automatically dereference scalar references passed this way. For other references content() will return the reference itself and add_content() will refuse to do anything. This returns the charset used by the content in the message. The charset is either found as the charset attribute of the \*(C`Content-Type\*(C' header or by guessing. See http://www.w3.org/TR/REC-html40/charset.html#spec-char-encoding <http://www.w3.org/TR/REC-html40/charset.html#spec-char-encoding> for details about how charset is determined. Returns the content with any \*(C`Content-Encoding\*(C' undone and for textual content the raw content encoded to Perl's Unicode strings. If the \*(C`Content-Encoding\*(C' or \*(C`charset\*(C' of the message is unknown this method will fail by returning \*(C`undef\*(C'. The following options can be specified.

This override the charset parameter for text content. The value \*(C`none\*(C' can used to suppress decoding of the charset. This override the default charset guessed by content_charset() or if that fails \*(L"\s-1ISO-8859-1\s0\*(R". If decoding fails because the charset specified in the Content-Type header isn't recognized by Perl's Encode module, then try decoding using this charset instead of failing. The \*(C`alt_charset\*(C' might be specified as \*(C`none\*(C' to simply return the string without any decoding of charset as alternative. Abort decoding if malformed characters is found in the content. By default you get the substitution character (\*(L"\x{\s-1FFFD\s0}\*(R") in place of malformed characters. If \s-1TRUE\s0 then raise an exception if not able to decode content. Reason might be that the specified \*(C`Content-Encoding\*(C' or \*(C`charset\*(C' is not supported. If this option is \s-1FALSE\s0, then decoded_content() will return \*(C`undef\*(C' on errors, but will still set $@. If \s-1TRUE\s0 then a reference to decoded content is returned. This might be more efficient in cases where the decoded content is identical to the raw content as no data copying is required in this case.

HTTP::Message::decodable()

This returns the encoding identifiers that decoded_content() can process. In scalar context returns a comma separated string of identifiers. This value is suitable for initializing the \*(C`Accept-Encoding\*(C' request header field. This method tries to replace the content of the message with the decoded version and removes the \*(C`Content-Encoding\*(C' header. Returns \s-1TRUE\s0 if successful and \s-1FALSE\s0 if not. If the message does not have a \*(C`Content-Encoding\*(C' header this method does nothing and returns \s-1TRUE\s0. Note that the content of the message is still bytes after this method has been called and you still need to call decoded_content() if you want to process its content as a string. Apply the given encodings to the content of the message. Returns \s-1TRUE\s0 if successful. The \*(L"identity\*(R" (non-)encoding is always supported; other currently supported encodings, subject to availability of required additional modules, are \*(L"gzip\*(R", \*(L"deflate\*(R", \*(L"x-bzip2\*(R" and \*(L"base64\*(R". A successful call to this function will set the \*(C`Content-Encoding\*(C' header. Note that \*(C`multipart/*\*(C' or \*(C`message/*\*(C' messages can't be encoded and this method will croak if you try. Messages can be composite, i.e. contain other messages. The composite messages have a content type of \*(C`multipart/*\*(C' or \*(C`message/*\*(C'. This method give access to the contained messages. The argumentless form will return a list of \*(C`HTTP::Message\*(C' objects. If the content type of $msg is not \*(C`multipart/*\*(C' or \*(C`message/*\*(C' then this will return the empty list. In scalar context only the first object is returned. The returned message parts should be regarded as read-only (future versions of this library might make it possible to modify the parent by modifying the parts). If the content type of $msg is \*(C`message/*\*(C' then there will only be one part returned. If the content type is \*(C`message/http\*(C', then the return value will be either an \*(C`HTTP::Request\*(C' or an \*(C`HTTP::Response\*(C' object. If a @parts argument is given, then the content of the message will be modified. The array reference form is provided so that an empty list can be provided. The @parts array should contain \*(C`HTTP::Message\*(C' objects. The @parts objects are owned by $mess after this call and should not be modified or made part of other messages. When updating the message with this method and the old content type of $mess is not \*(C`multipart/*\*(C' or \*(C`message/*\*(C', then the content type is set to \*(C`multipart/mixed\*(C' and all other content headers are cleared. This method will croak if the content type is \*(C`message/*\*(C' and more than one part is provided. This will add a part to a message. The $part argument should be another \*(C`HTTP::Message\*(C' object. If the previous content type of $mess is not \*(C`multipart/*\*(C' then the old content (together with all content headers) will be made part #1 and the content type made \*(C`multipart/mixed\*(C' before the new part is added. The $part object is owned by $mess after this call and should not be modified or made part of other messages. There is no return value. Will clear the headers and set the content to the empty string. There is no return value Sets the \s-1HTTP\s0 protocol used for the message. The protocol() is a string like \*(C`HTTP/1.0\*(C' or \*(C`HTTP/1.1\*(C'. Returns a copy of the message object. Returns the message formatted as a single string. The optional $eol parameter specifies the line ending sequence to use. The default is \*(L"\n\*(R". If no $eol is given then as_string will ensure that the returned string is newline terminated (even when the message content is not). No extra newline is appended if an explicit $eol is passed. Returns the message formatted as a string. In void context print the string. This differs from \*(C`$mess->as_string\*(C' in that it escapes the bytes of the content so that it's safe to print them and it limits how much content to print. The escapes syntax used is the same as for Perl's double quoted strings. If there is no content the string \*(L"(no content)\*(R" is shown in its place. Options to influence the output can be passed as key/value pairs. The following options are recognized:

How much of the content to show. The default is 512. Set this to 0 for unlimited. If the content is longer then the string is chopped at the limit and the string \*(L"...\n(### more bytes not shown)\*(R" appended. Replaces the \*(L"(no content)\*(R" marker. A string that will be prefixed to each line of the dump.

All methods unknown to \*(C`HTTP::Message\*(C' itself are delegated to the \*(C`HTTP::Headers\*(C' object that is part of every message. This allows convenient access to these methods. Refer to HTTP::Headers for details of these methods:

$mess->header( $field => $val ) $mess->push_header( $field => $val ) $mess->init_header( $field => $val ) $mess->remove_header( $field ) $mess->remove_content_headers $mess->header_field_names $mess->scan( \&doit )

$mess->date $mess->expires $mess->if_modified_since $mess->if_unmodified_since $mess->last_modified $mess->content_type $mess->content_encoding $mess->content_length $mess->content_language $mess->title $mess->user_agent $mess->server $mess->from $mess->referer $mess->www_authenticate $mess->authorization $mess->proxy_authorization $mess->authorization_basic $mess->proxy_authorization_basic

COPYRIGHT

Copyright 1995-2004 Gisle Aas.

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