Hippo2000 (2000/7/28)
HTTP::Headers::Utilモジュールなのです。
作者はGisle Aasさんです。メールで許可をいただきました。
HTTP::Headers::Util - ヘッダの値を解析するユーティリティ関数
use HTTP::Headers::Util qw(split_header_words);
@values = split_header_words($h->header("Content-Type"));
このモジュールは正しいHTTPヘッダ値の解析と組みたてを助ける2,3の関数を提供します。デフォルトでは何も関数をエクスポートしません。
以下の関数がつかえます:
もし複数の値が入った@header_valuesが引数として渡されると、カンマ","で区切られた1つの値であるかのように扱われます。
つまりこの関数は以下の文法に従ったヘッダ・フィールドを解析するのに便利です。(HTTP/1.1仕様をからのBNF、しかしトークンへの要求は緩めています)。
headers = #header header = (token | parameter) *( [";"] (token | parameter))
token = 1*<any CHAR except CTLs or separators>
separators = "(" | ")" | "<" | ">" | "@"
| "," | ";" | ":" | "\" | <">
| "/" | "[" | "]" | "?" | "="
| "{" | "}" | SP | HT
quoted-string = ( <"> *(qdtext | quoted-pair ) <"> ) qdtext = <any TEXT except <">> quoted-pair = "\" CHAR
parameter = attribute "=" value attribute = token value = token | quoted-string
各header はキー/値の組の無名配列で表されます。単純なトークンの値は(パラメータの一部ではなく)はundefです。文法的に正しくないヘッダは、必らずしもあなたの要求通りには解析されません。
幾つかの例で説明するとより簡単です:
split_header_words('foo="bar"; port="80,81"; discard, bar=baz')
split_header_words('text/html; charset="iso-8859-1");
split_header_words('Basic realm="\"foo\\bar\""');
これは以下のように返します。
[foo=>'bar', port=>'80,81', discard=> undef], [bar=>'baz' ] ['text/html' => undef, charset => 'iso-8859-1'] [Basic => undef, realm => '"foo\bar"']
例:
join_header_words(["text/plain" => undef, charset => "iso-8859/1"]);
join_header_words(""text/plain" => undef, charset => "iso-8859/1");
両方とも以下のような文字列を返します。
text/plain; charset="iso-8859/1"
Copyright 1997-1998, Gisle Aas
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
ご意見、ご質問はこちらの掲示板で受け付けています。
またメールは河馬屋(Nifty)にお願いします。