名前¶
HTTP::Message - HTTP style message (base class)
HTTP::Message - HTTP 形式のメッセージ (基底クラス)
概要¶
use base 'HTTP::Message';
説明¶
An HTTP::Message object contains some headers and a content body. The following methods are available:
HTTP::Message オブジェクトには幾つかのヘッダとコンテンツの本体が 入っています。 以下のメソッドが利用できます:
- $mess = HTTP::Message->new
- $mess = HTTP::Message->new( $headers )
- $mess = HTTP::Message->new( $headers, $content )
-
This constructs a new message object. Normally you would want construct
HTTP::RequestorHTTP::Responseobjects instead.これは新しいメッセージオブジェクトを構築します。 普通は代わりに
HTTP::RequestまたはHTTP::Responseオブジェクトを 構築したいでしょう。The optional $header argument should be a reference to an
HTTP::Headersobject or a plain array reference of key/value pairs. If anHTTP::Headersobject 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.オプションの $header 引数は
HTTP::Headersオブジェクトへのリファレンスか、 キー/値の組へのリファレンスの配列を取ります。HTTP::Headersオブジェクトを指定した場合は、これのコピーが 構築されるメッセージに組み込まれます (つまり、後でオブジェクトを変更しても メッセージには影響を与えません)。The optional $content argument should be a string of bytes.
オプションの $content 引数はバイト文字列であるべきです。
- $mess = HTTP::Message->parse( $str )
-
This constructs a new message object by parsing the given string.
与えられた文字列をパースすることで新しいメッセージオブジェクトを 作成します。
- $mess->headers
-
Returns the embedded
HTTP::Headersobject.埋め込まれた
HTTP::Headersオブジェクトを返します。 - $mess->headers_as_string
- $mess->headers_as_string( $eol )
-
Call the as_string() method for the headers in the message. This will be the same as
メッセージの中のヘッダのために as_string() を呼び出します。 これは以下のものと同様ですが
$mess->headers->as_stringbut it will make your program a whole character shorter :-)
あなたのプログラムの文字数が減ります :-)
- $mess->content
- $mess->content( $bytes )
-
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.
引数が与えられていれば、content() メソッドは生の内容を設定します。 引数が与えられなければ、内容は触られません。 いずれの場合も元の生の内容は返されます。
Note that the content should be a string of bytes. Strings in perl can contain characters outside the range of a byte. The
Encodemodule can be used to turn such strings into a string of bytes.内容はバイト文字列であるべきであることに注意してください。 Perl での文字列はバイトの範囲を超える文字を含むことができます。 そのような文字列をバイト文字列を変換するには
Encodeモジュールが 使えます。 - $mess->add_content( $bytes )
-
The add_content() methods appends more data bytes to the end of the current content buffer.
add_content() メソッドは現在のコンテンツの末尾にさらにバイトデータを 追加します。
- $mess->add_content_utf8( $string )
-
The add_content_utf8() method appends the UTF-8 bytes representing the string to the end of the current content buffer.
add_content_utf8() メソッドは、$string で表現される UTF-8 バイトを 現在の内容バッファの末尾に追加します。
- $mess->content_ref
- $mess->content_ref( \$bytes )
-
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:
content_ref() メソッドは内容バッファ文字列へのリファレンスを返します。 コンテンツが巨大であれば、この方法でコンテンツにアクセスするのはより 効率的かもしれません。 そしてコンテンツの直接操作するためにすら使うことが出来ます。 例えば:
${$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.
引数が渡されると、それを外部ソースへリファレンスとして内容を 設定します。 content() メソッドと add_content() メソッドは、この方法で渡された スカラリファレンスを自動的にデリファレンスします。 その他のリファレンスの場合、content() はリファレンス自身を返し、 add_content() は何もしません。
- $mess->decoded_content( %options )
-
Returns the content with any
Content-Encodingundone and the raw content encoded to perl's Unicode strings. If theContent-Encodingorcharsetof the message is unknown this method will fail by returningundef.Content-Encodingが未処理の、perl の Unicode 文字列でエンコードされた 生の内容を返します。 メッセージのContent-Encodingあるいはcharsetが不明の場合、 このメソッドはundefを返して失敗します。The following options can be specified.
以下のオプションが指定できます。
charset-
This override the charset parameter for text content. The value
nonecan used to suppress decoding of the charset.これはテキストの内容の文字集合パラメータを上書きします。 文字セットのデコードを抑制するために
noneという値が使えます。 default_charset-
This override the default charset of "ISO-8859-1".
これはデフォルトの文字集合である "ISO-8859-1" を上書きします。
charset_strict-
Abort decoding if malformed characters is found in the content. By default you get the substitution character ("\x{FFFD}") in place of malformed characters.
もし内容に不正な文字が見つかると、デコードを中断します。 デフォルトでは、不正な文字の位置には代わりの文字 ("\x{FFFD}") が 使われます。
raise_error-
If TRUE then raise an exception if not able to decode content. Reason might be that the specified
Content-Encodingorcharsetis not supported. If this option is FALSE, then decoded_content() will returnundefon errors, but will still set $@.この値が真の場合、内容をデコードできない場合に例外が発生します。 理由は、
Content-Encodingやcharsetに指定されたものに 対応していないことかもしれません。 この値が偽の場合、decoded_content() はエラー時にはundefを 返しますが、それでも $@ は設定されます。 ref-
If TRUE 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.
この値が真の場合、デコードされた内容へのリファレンスが返されます。 元の内容とデコードされた内容が同じ場合、データのコピーが必要ないので、 これを設定するとより効率的になるでしょう。
- $mess->parts
- $mess->parts( @parts )
- $mess->parts( \@parts )
-
Messages can be composite, i.e. contain other messages. The composite messages have a content type of
multipart/*ormessage/*. This method give access to the contained messages.メッセージは合成できます (他のメッセージを含むことができます)。 合成メッセージは
multipart/*やmessage/*のコンテントタイプを 持ちます。 このメソッドは含まれているメッセージにアクセスします。The argumentless form will return a list of
HTTP::Messageobjects. If the content type of $msg is notmultipart/*ormessage/*then this will return the empty list. In scalar context only the first object is returned. The returned message parts should be regarded as are read only (future versions of this library might make it possible to modify the parent by modifying the parts).引数なし形式の場合は
HTTP::Messageオブジェクトのリストを返します。 $msg のコンテントタイプがmultipart/*でもmessage/*でもない場合は 空リストが返されます。 スカラコンテキストでは最初のオブジェクトのみが返されます。 返されたメッセージ部品は読み込み専用と考えるべきです (このライブラリの将来のバージョンでは、部品を変更することで親を 変更できるようになるかもしれません)。If the content type of $msg is
message/*then there will only be one part returned.$msg のコンテントタイプが
message/*なら、一つの部品だけが 返されます。If the content type is
message/http, then the return value will be either anHTTP::Requestor anHTTP::Responseobject.コンテントタイプが
message/httpなら、返された値はHTTP::RequestオブジェクトかHTTP::Responseオブジェクトです。If an @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::Messageobjects. The @parts objects are owned by $mess after this call and should not be modified or made part of other messages.@parts 引数が与えられると、メッセージの内容は変更されます。 空リストを提供できるように、配列リファレンス形式で提供されます。 @parts 配列は
HTTP::Messageオブジェクトを含んでいる必要があります。 @parts オブジェクトはこの呼び出しの後 $mess によって所有され、 修正されたり、他のメッセージの部品となったりはしません。When updating the message with this method and the old content type of $mess is not
multipart/*ormessage/*, then the content type is set tomultipart/mixedand all other content headers are cleared.このメソッドによってメッセージが更新され、$mess の古い コンテントタイプが
multipart/*でもmessage/*でもない場合、 コンテントタイプはmultipart/mixedに設定され、その他の全ての コンテントヘッダはクリアされます。This method will croak if the content type is
message/*and more than one part is provided.このメソッドは、コンテントタイプが
message/*で、複数の部品が 提供された場合、croak します。 - $mess->add_part( $part )
-
This will add a part to a message. The $part argument should be another
HTTP::Messageobject. If the previous content type of $mess is notmultipart/*then the old content (together with all content headers) will be made part #1 and the content type mademultipart/mixedbefore 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.メッセージに部品を追加します。 $part 引数はもう一つの
HTTP::Messageオブジェクトです。 $mess の以前のコンテントタイプがmultipart/*でない場合、 古い内容(と全てのコンテントヘッダ) は 1 番目の部品になり、新しい部品が 追加される前にコンテントタイプはmultipart/mixedになります。 $part オブジェクトはこの呼び出しの後 $mess によって所有され、 修正されたり、他のメッセージの部品となったりはしません。There is no return value.
返り値はありません。
- $mess->clear
-
Will clear the headers and set the content to the empty string. There is no return value
ヘッダをクリアし、内容を空文字列に設定します。 返り値はありません。
- $mess->protocol
- $mess->protocol( $proto )
-
Sets the HTTP protocol used for the message. The protocol() is a string like
HTTP/1.0orHTTP/1.1.そのメッセージに使われる HTTP プロトコルを設定します。 protocol() は
HTTP/1.0やHTTP/1.1のような文字列です。 - $mess->clone
-
Returns a copy of the message object.
メッセージオブジェクトのコピーを返します。
- $mess->as_string
- $mess->as_string( $eol )
-
Returns the message formatted as a single string.
単一の文字列の形でメッセージを返します。
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.
オプションの $eol 引数は、使用する行末シーケンスを指定します。 デフォルトは "\n" です。 $eol が与えられなかった場合は、(たとえメッセージの末尾に改行がなくても) 返される文字列が改行で終端されることが保証されます。 明示的に $eol が渡された場合は、改行は追加されません。
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:
HTTP::Message 自身が分からないすべてのメソッドは、 代わりに各メッセージの一部である HTTP::Headers オブジェクトに 委譲されます。 これは以下の便利メソッドへのアクセスを可能にします。 これらのメソッドについての詳細は HTTP::Headers を参照してください。
$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 1995-2004 Gisle Aas.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.