Codex

HTTP::Headers::Util

Section: User Contributed Perl Documentation (3pm)

Updated: 2012-02-16

Index?action=index Return to Main Contents


NAME

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

SYNOPSIS

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:

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 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).

Each header is represented by an anonymous array of key/value pairs. The keys will be all be forced to lower case. The value for a simple token (not part of a parameter) is . Syntactically incorrect headers will not necessarily be parsed as you would want.

This is easier to describe with some examples:

will return

If you don't want the function to convert tokens and attribute keys to lower case you can call it as instead (with a leading underscore).

:

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.

Example:

will both return the string:

:

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.


Index

NAME

SYNOPSIS

DESCRIPTION

COPYRIGHT