libwww-perl-5.813 > HTTP::Headers::Util
libwww-perl-5.813

名前

HTTP::Headers::Util - Header value parsing utility functions

HTTP::Headers::Util - ヘッダの値を解析するユーティリティ関数

概要

  use HTTP::Headers::Util qw(split_header_words);
  @values = split_header_words($h->header("Content-Type"));

説明

This module provides a few functions that helps parsing and construction of valid HTTP header values. None of the functions are exported by default.

このモジュールは正しい HTTP ヘッダ値の解析と組みたてを助けるいくつかの関数を 提供します。 デフォルトでは何も関数をエクスポートしません。

The following functions are available:

以下の関数がつかえます:

split_header_words( @header_values )

This function will parse the header values given as argument into a list of anonymous arrays containing key/value pairs. The function knows how to deal with ",", ";" and "=" as well as quoted values after "=". A list of space separated tokens are parsed as if they were separated by ";".

この関数は引数で与えられたヘッダの値をキー/値の組が入った無名配列の リストに解析します。 この関数は ",", ";", "=" を、"=" の後のクォートされた値と同じくらい 扱い方をよく知っています。 空白で区切られたトークンは ";" で区切られているように解析されます。

If the @header_values passed as argument contains multiple values, then they are treated as if they were a single value separated by comma ",".

もし複数の値が入った @header_values が引数として渡されると、カンマ "," で区切られた一つの値であるかのように扱われます。

This means that this function is useful for parsing header fields that follow this syntax (BNF as from the HTTP/1.1 specification, but we relax the requirement for tokens).

つまりこの関数は以下の文法に従ったヘッダフィールドを解析するのに便利です。 (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

Each header is represented by an anonymous array of key/value pairs. The value for a simple token (not part of a parameter) is undef. Syntactically incorrect headers will not necessary be parsed as you would want.

header はキー/値の組の無名配列で表されます。 単純なトークンの値は (パラメータの一部ではなく) は undef です。 文法的に正しくないヘッダは、必らずしもあなたの要求通りには解析されません。

This is easier to describe with some examples:

幾つかの例で説明するとより簡単です:

   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\\""');

will return

これは以下のように返します。

   [foo=>'bar', port=>'80,81', discard=> undef], [bar=>'baz' ]
   ['text/html' => undef, charset => 'iso-8859-1']
   [Basic => undef, realm => "\"foo\\bar\""]
join_header_words( @arrays )

This will do the opposite of the conversion done by split_header_words(). It takes a list of anonymous arrays as arguments (or a list of key/value pairs) and produces a single header value. Attribute values are quoted if needed.

これは split_header_words() によって行われる変換の反対をやります。 これは無名配列のリスト (あるいはキー/値の組のリスト) を引数として取ります。 そして一つのヘッダ値を作成します。 必要であれば属性値はクォートされます。

Example:

例:

   join_header_words(["text/plain" => undef, charset => "iso-8859/1"]);
   join_header_words("text/plain" => undef, charset => "iso-8859/1");

will both return the string:

両方とも以下のような文字列を返します。

   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.