home *** CD-ROM | disk | FTP | other *** search
-
- <HTML>
- <HEAD>
- <TITLE>HTTP::Headers::Util - Header value parsing utility functions</TITLE>
- <LINK REL="stylesheet" HREF="../../../../Active.css" TYPE="text/css">
- <LINK REV="made" HREF="mailto:">
- </HEAD>
-
- <BODY>
- <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
- <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
- <STRONG><P CLASS=block> HTTP::Headers::Util - Header value parsing utility functions</P></STRONG>
- </TD></TR>
- </TABLE>
-
- <A NAME="__index__"></A>
- <!-- INDEX BEGIN -->
-
- <UL>
-
- <LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
-
- <LI><A HREF="#synopsis">SYNOPSIS</A></LI>
- <LI><A HREF="#description">DESCRIPTION</A></LI>
- <LI><A HREF="#copyright">COPYRIGHT</A></LI>
- </UL>
- <!-- INDEX END -->
-
- <HR>
- <P>
- <H1><A NAME="name">NAME</A></H1>
- <P>HTTP::Headers::Util - Header value parsing utility functions</P>
- <P>
- <HR>
- <H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
- <UL>
- <LI>Linux</LI>
- <LI>Solaris</LI>
- <LI>Windows</LI>
- </UL>
- <HR>
- <H1><A NAME="synopsis">SYNOPSIS</A></H1>
- <PRE>
- use HTTP::Headers::Util qw(split_header_words);
- @values = split_header_words($h->header("Content-Type"));</PRE>
- <P>
- <HR>
- <H1><A NAME="description">DESCRIPTION</A></H1>
- <P>This module provides a few functions that helps parsing and
- construction of valid HTTP header values. None of the functions are
- exported by default.</P>
- <P>The following functions are available:</P>
- <DL>
- <DT><STRONG><A NAME="item_split_header_words">split_header_words( @header_values )</A></STRONG><BR>
- <DD>
- 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 ``;''.
- <P>If the @header_values passed as argument contains multiple values,
- then they are treated as if they were a single value separated by
- comma ``,''.</P>
- <P>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).</P>
- <PRE>
- headers = #header
- header = (token | parameter) *( [";"] (token | parameter))</PRE>
- <PRE>
- token = 1*<any CHAR except CTLs or separators>
- separators = "(" | ")" | "<" | ">" | "@"
- | "," | ";" | ":" | "\" | <">
- | "/" | "[" | "]" | "?" | "="
- | "{" | "}" | SP | HT</PRE>
- <PRE>
- quoted-string = ( <"> *(qdtext | quoted-pair ) <"> )
- qdtext = <any TEXT except <">>
- quoted-pair = "\" CHAR</PRE>
- <PRE>
- parameter = attribute "=" value
- attribute = token
- value = token | quoted-string</PRE>
- <P>Each <EM>header</EM> is represented by an anonymous array of key/value
- pairs. The value for a simple token (not part of a parameter) is <A HREF="../../../../lib/Pod/perlfunc.html#item_undef"><CODE>undef</CODE></A>.
- Syntactically incorrect headers will not necessary be parsed as you
- would want.</P>
- <P>This is easier to describe with some examples:</P>
- <PRE>
- 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\""');</PRE>
- <P>will return</P>
- <PRE>
- [foo=>'bar', port=>'80,81', discard=> undef], [bar=>'baz' ]
- ['text/html' => undef, charset => 'iso-8859-1']
- [Basic => undef, realm => '"foo\bar"']</PRE>
- <P></P>
- <DT><STRONG><A NAME="item_join_header_words">join_header_words( @arrays )</A></STRONG><BR>
- <DD>
- 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.
- <P>Example:</P>
- <PRE>
- join_header_words(["text/plain" => undef, charset => "iso-8859/1"]);
- join_header_words(""text/plain" => undef, charset => "iso-8859/1");</PRE>
- <P>will both return the string:</P>
- <PRE>
- text/plain; charset="iso-8859/1"</PRE>
- <P></P></DL>
- <P>
- <HR>
- <H1><A NAME="copyright">COPYRIGHT</A></H1>
- <P>Copyright 1997-1998, Gisle Aas</P>
- <P>This library is free software; you can redistribute it and/or
- modify it under the same terms as Perl itself.</P>
- <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
- <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
- <STRONG><P CLASS=block> HTTP::Headers::Util - Header value parsing utility functions</P></STRONG>
- </TD></TR>
- </TABLE>
-
- </BODY>
-
- </HTML>
-