HTTP::Headers::Util - Header value parsing utility functions
use HTTP::Headers::Util qw(split_header_words); @values = split_header_words($h->header("Content-Type"));
The following functions are available:
If the @header_values passed as argument contains multiple values, then they are treated as if they were a single value separated by comma ``,''.
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).
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.
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\""]
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"
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Закладки на сайте Проследить за страницей |
Created 1996-2024 by Maxim Chirkov Добавить, Поддержать, Вебмастеру |