名前¶
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->content_charset
-
This returns the charset used by the content in the message. The charset is either found as the charset attribute of the
Content-Typeheader or by guessing.これはメッセージの内容で使われている文字集合を返します。 文字集合は、
Content-Typeヘッダの charset 属性にあるものか、 推測によるものです。See http://www.w3.org/TR/REC-html40/charset.html#spec-char-encoding for details about how charset is determined.
文字集合がどのように決定されるかに関する詳細は、 http://www.w3.org/TR/REC-html40/charset.html#spec-char-encoding を 参照してください。
- $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 guessed by content_charset() or if that fails "ISO-8859-1".
これは、content_charset() による推測か、 それに失敗したら "ISO-8859-1" となるデフォルトを上書きします。
alt_charset-
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
alt_charsetmight be specified asnoneto simply return the string without any decoding of charset as alternative.Content-Type ヘッダで指定された文字集合が Perl の Encode モジュールで 認識されなかったためにデコードが失敗すると、 失敗する代わりにこの文字集合を使ってデコードしようとします。 代替策としての文字集合のでのデコードなしに単に文字列を返すために、
alt_charsetにnoneを指定できます。 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->decodable
- HTTP::Message::decodable()
-
This returns the encoding identifiers that decoded_content() can process. In scalar context returns a comma separated string of identifiers.
これは、decoded_content() が処理できるエンコーディング識別子を返します。 スカラコンテキストでは、カンマ区切りの識別子の文字列を返します。
This value is suitable for initializing the
Accept-Encodingrequest header field.この値は
Accept-Encodingリクエストヘッダフィールドを 初期化するのに適しています。 - $mess->decode
-
This method tries to replace the content of the message with the decoded version and removes the
Content-Encodingheader. Returns TRUE if successful and FALSE if not.このメソッドは、メッセージの内容をデコードされたものに置き換えて、
Content-Encodingヘッダを削除しようとします。 成功すれば真を、さもなければ偽を返します。If the message does not have a
Content-Encodingheader this method does nothing and returns TRUE.メッセージに
Content-Encodingヘッダがなければ、何もせずに真を返します。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.
メソッドが呼び出された後もメッセージの内容はバイトのままで、 内容を文字列として処理したいときはやはり decoded_content() を 呼び出す必要があることに注意してください。
- $mess->encode( $encoding, ... )
-
Apply the given encodings to the content of the message. Returns TRUE if successful. The "identity" (non-)encoding is always supported; other currently supported encodings, subject to availability of required additional modules, are "gzip", "deflate", "x-bzip2" and "base64".
メッセージの内容に与えられたエンコーディングを適用します。 成功すると真を返します。 "identity" (非)エンコーディングは常に対応しています; 必要な追加モジュールが利用可能であることを条件として、現在の所 対応しているその他のエンコーディングは、 "gzip", "deflate", "x-bzip2", "base64" です。
A successful call to this function will set the
Content-Encodingheader.この関数の呼び出しに成功すると
Content-Encodingヘッダを設定します。Note that
multipart/*ormessage/*messages can't be encoded and this method will croak if you try.multipart/*やmessage/*メッセージはエンコードできず、 しようとするとこのメソッドは croak します。 - $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 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 が渡された場合は、改行は追加されません。
- $mess->dump( %opt )
-
Returns the message formatted as a string. In void context print the string.
文字列としてフォーマットされたメッセージを返します。 無効コンテキストでは文字列を表示します。
This differs from
$mess->as_stringin 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.これは、安全に表示できるように内容のバイトをエスケープすることと、 内容をどれくらい表示するかを制限することが
$mess->as_stringと 違う点です。 使われるエスケープ文法は、Perl のダブルクォート文字列のものと同じです。 内容がない場合、その場所に "(no content)" という文字列が入ります。Options to influence the output can be passed as key/value pairs. The following options are recognized:
キー/値のペアとして、出力に影響を与えるオプションを渡せます。 以下のオプションを認識します:
- maxlength => $num
-
How much of the content to show. The default is 512. Set this to 0 for unlimited.
内容をどれくらい表示するか。 デフォルトは 512 です。 無制限にするには 0 に設定します。
If the content is longer then the string is chopped at the limit and the string "...\n(### more bytes not shown)" appended.
内容がこれより長い場合、文字列はこの制限で切り落とされ、 "...\n(### more bytes not shown)" という文字列が追加されます。
- prefix => $str
-
A string that will be prefixed to each line of the dump.
ダンプの各行の前に前置される文字列。
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.