Manual Pages for UNIX Darwin command on man HTTP::Headers::Util
MyWebUniversity

Manual Pages for UNIX Darwin command on man HTTP::Headers::Util

HTTP::Headers::Util(3)User Contributed Perl DocumentationHTTP::Headers::Util(3)

NAME

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

SYNOPSIS

use HTTP::Headers::Util qw(splitheaderwords);

@values = splitheaderwords($h->header("Content-Type"));

DESCRIPTION

This module provides a few functions that helps parsing and construction of valid HTTP header values. None of the functions are exported by default. The following functions are available: splitheaderwords( @headervalues ) 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 @headervalues 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* separators = "(" | ")" | "<" | ">" | "@" | "," | ";" | ":" | "\" | <"> | "/" | "[" | "]" | "?" | "=" | "{" | "}" | SP | HT

quoted-string = ( <"> *(qdtext | quoted-pair ) <"> )

qdtext = >

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: splitheaderwords('foo="bar"; port="80,81"; discard, bar=baz');

splitheaderwords('text/html; charset="iso-8859-1"');

splitheaderwords('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\""] joinheaderwords( @arrays ) This will do the opposite of the conversion done by splitheaderwords(). 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. Example:

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

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

will both return the string:

text/plain; charset="iso-8859/1"

COPYRIGHT

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.

perl v5.8.8 2003-10-23 HTTP::Headers::Util(3)




Contact us      |      About us      |      Term of use      |       Copyright © 2000-2019 MyWebUniversity.com ™