248 lines
5.0 KiB
HTML
248 lines
5.0 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of HTTP::Headers::Util</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>HTTP::Headers::Util</H1>
|
|
Section: User Contributed Perl Documentation (3pm)<BR>Updated: 2020-02-29<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
HTTP::Headers::Util - Header value parsing utility functions
|
|
<A NAME="lbAC"> </A>
|
|
<H2>VERSION</H2>
|
|
|
|
|
|
|
|
version 6.22
|
|
<A NAME="lbAD"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
|
|
|
|
|
|
|
|
<PRE>
|
|
use HTTP::Headers::Util qw(split_header_words);
|
|
@values = split_header_words($h->header("Content-Type"));
|
|
|
|
</PRE>
|
|
|
|
|
|
<A NAME="lbAE"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
|
|
|
|
This module provides a few functions that helps parsing and
|
|
construction of valid <FONT SIZE="-1">HTTP</FONT> header values. None of the functions are
|
|
exported by default.
|
|
<P>
|
|
|
|
The following functions are available:
|
|
<DL COMPACT>
|
|
<DT id="1">split_header_words( @header_values )<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 <TT>@header_values</TT> passed as argument contains multiple values,
|
|
then they are treated as if they were a single value separated by
|
|
comma ``,''.
|
|
|
|
|
|
<P>
|
|
|
|
|
|
This means that this function is useful for parsing header fields that
|
|
follow this syntax (<FONT SIZE="-1">BNF</FONT> as from the <FONT SIZE="-1">HTTP/1.1</FONT> specification, but we relax
|
|
the requirement for tokens).
|
|
|
|
|
|
<P>
|
|
|
|
|
|
|
|
|
|
<PRE>
|
|
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
|
|
|
|
</PRE>
|
|
|
|
|
|
|
|
|
|
<P>
|
|
|
|
|
|
Each <I>header</I> 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 <TT>"undef"</TT>.
|
|
Syntactically incorrect headers will not necessarily be parsed as you
|
|
would want.
|
|
|
|
|
|
<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>
|
|
|
|
|
|
If you don't want the function to convert tokens and attribute keys to
|
|
lower case you can call it as <TT>"_split_header_words"</TT> instead (with a
|
|
leading underscore).
|
|
<DT id="2">join_header_words( @arrays )<DD>
|
|
|
|
|
|
|
|
|
|
This will do the opposite of the conversion done by <B>split_header_words()</B>.
|
|
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>
|
|
|
|
|
|
</DL>
|
|
<A NAME="lbAF"> </A>
|
|
<H2>AUTHOR</H2>
|
|
|
|
|
|
|
|
Gisle Aas <<A HREF="mailto:gisle@activestate.com">gisle@activestate.com</A>>
|
|
<A NAME="lbAG"> </A>
|
|
<H2>COPYRIGHT AND LICENSE</H2>
|
|
|
|
|
|
|
|
This software is copyright (c) 1994-2017 by Gisle Aas.
|
|
<P>
|
|
|
|
This is free software; you can redistribute it and/or modify it under
|
|
the same terms as the Perl 5 programming language system itself.
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="3"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="4"><A HREF="#lbAC">VERSION</A><DD>
|
|
<DT id="5"><A HREF="#lbAD">SYNOPSIS</A><DD>
|
|
<DT id="6"><A HREF="#lbAE">DESCRIPTION</A><DD>
|
|
<DT id="7"><A HREF="#lbAF">AUTHOR</A><DD>
|
|
<DT id="8"><A HREF="#lbAG">COPYRIGHT AND LICENSE</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:45 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|