1HTTP::Headers::Util(3)User Contributed Perl DocumentationHTTP::Headers::Util(3)
2
3
4

NAME

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

VERSION

9       version 6.18
10

SYNOPSIS

12         use HTTP::Headers::Util qw(split_header_words);
13         @values = split_header_words($h->header("Content-Type"));
14

DESCRIPTION

16       This module provides a few functions that helps parsing and
17       construction of valid HTTP header values.  None of the functions are
18       exported by default.
19
20       The following functions are available:
21
22       split_header_words( @header_values )
23           This function will parse the header values given as argument into a
24           list of anonymous arrays containing key/value pairs.  The function
25           knows how to deal with ",", ";" and "=" as well as quoted values
26           after "=".  A list of space separated tokens are parsed as if they
27           were separated by ";".
28
29           If the @header_values passed as argument contains multiple values,
30           then they are treated as if they were a single value separated by
31           comma ",".
32
33           This means that this function is useful for parsing header fields
34           that follow this syntax (BNF as from the HTTP/1.1 specification,
35           but we relax the requirement for tokens).
36
37             headers           = #header
38             header            = (token | parameter) *( [";"] (token | parameter))
39
40             token             = 1*<any CHAR except CTLs or separators>
41             separators        = "(" | ")" | "<" | ">" | "@"
42                               | "," | ";" | ":" | "\" | <">
43                               | "/" | "[" | "]" | "?" | "="
44                               | "{" | "}" | SP | HT
45
46             quoted-string     = ( <"> *(qdtext | quoted-pair ) <"> )
47             qdtext            = <any TEXT except <">>
48             quoted-pair       = "\" CHAR
49
50             parameter         = attribute "=" value
51             attribute         = token
52             value             = token | quoted-string
53
54           Each header is represented by an anonymous array of key/value
55           pairs.  The keys will be all be forced to lower case.  The value
56           for a simple token (not part of a parameter) is "undef".
57           Syntactically incorrect headers will not necessarily be parsed as
58           you would want.
59
60           This is easier to describe with some examples:
61
62              split_header_words('foo="bar"; port="80,81"; DISCARD, BAR=baz');
63              split_header_words('text/html; charset="iso-8859-1"');
64              split_header_words('Basic realm="\\"foo\\\\bar\\""');
65
66           will return
67
68              [foo=>'bar', port=>'80,81', discard=> undef], [bar=>'baz' ]
69              ['text/html' => undef, charset => 'iso-8859-1']
70              [basic => undef, realm => "\"foo\\bar\""]
71
72           If you don't want the function to convert tokens and attribute keys
73           to lower case you can call it as "_split_header_words" instead
74           (with a leading underscore).
75
76       join_header_words( @arrays )
77           This will do the opposite of the conversion done by
78           split_header_words().  It takes a list of anonymous arrays as
79           arguments (or a list of key/value pairs) and produces a single
80           header value.  Attribute values are quoted if needed.
81
82           Example:
83
84              join_header_words(["text/plain" => undef, charset => "iso-8859/1"]);
85              join_header_words("text/plain" => undef, charset => "iso-8859/1");
86
87           will both return the string:
88
89              text/plain; charset="iso-8859/1"
90

AUTHOR

92       Gisle Aas <gisle@activestate.com>
93
95       This software is copyright (c) 1994-2017 by Gisle Aas.
96
97       This is free software; you can redistribute it and/or modify it under
98       the same terms as the Perl 5 programming language system itself.
99
100
101
102perl v5.28.1                      2018-06-05            HTTP::Headers::Util(3)
Impressum