HTTP::Message(3) | User Contributed Perl Documentation | HTTP::Message(3) |
HTTP::Message - HTTP style message (base class)
version 6.22
use base 'HTTP::Message';
An "HTTP::Message" object contains some headers and a content body. The following methods are available:
The optional $header argument should be a reference to an "HTTP::Headers" object or a plain array reference of key/value pairs. If an "HTTP::Headers" 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.
$mess->headers->as_string
but it will make your program a whole character shorter :-)
If the "undef" argument is given, the content is reset to its default value, which is an empty string.
Note that the content should be a string of bytes. Strings in perl can contain characters outside the range of a byte. The "Encode" module can be used to turn such strings into a string of bytes.
${$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.
See <http://www.w3.org/TR/REC-html40/charset.html#spec-char-encoding> for details about how charset is determined.
The following options can be specified.
This value is suitable for initializing the "Accept-Encoding" request header field.
If the message does not have a "Content-Encoding" header this method does nothing and returns TRUE.
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.
A successful call to this function will set the "Content-Encoding" header.
Note that "multipart/*" or "message/*" messages can't be encoded and this method will croak if you try.
The argumentless form will return a list of "HTTP::Message" objects. If the content type of $msg is not "multipart/*" or "message/*" 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 "message/*" then there will only be one part returned.
If the content type is "message/http", then the return value will be either an "HTTP::Request" or an "HTTP::Response" 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 "HTTP::Message" 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 "multipart/*" or "message/*", then the content type is set to "multipart/mixed" and all other content headers are cleared.
This method will croak if the content type is "message/*" and more than one part is provided.
There is no return value.
The optional $eol parameter specifies the line ending sequence to use. The default is "\n". 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.
This differs from "$mess->as_string" 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 "(no content)" is shown in its place.
Options to influence the output can be passed as key/value pairs. The following options are recognized:
If the content is longer then the string is chopped at the limit and the string "...\n(### more bytes not shown)" appended.
All methods unknown to "HTTP::Message" itself are delegated to the "HTTP::Headers" 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
Gisle Aas <gisle@activestate.com>
This software is copyright (c) 1994-2017 by Gisle Aas.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
2020-02-24 | perl v5.34.0 |