-
-
14 Jun 2022 14:19:16 UTC
- Distribution: HTTP-Message
- Module version: 6.37
- Source (raw)
- Browse (raw)
- Changes
- Homepage
- How to Contribute
- Repository
- Issues (56)
- Testers (1687 / 9 / 0)
- Kwalitee
Bus factor: 7- 95.51% Coverage
- License: perl_5
- Perl: v5.8.1
- Activity
24 month- Tools
- Download (88.82KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
and 85 contributors-
Gisle Aas
-
Adam Kennedy
-
Adam Sjogren
-
Alexey Tourbin
-
Alex Kapranoff
-
amire80
-
Andreas J. Koenig
-
Andrei Grechkin
-
Bill Mann
-
Brendan Byrd
-
Bron Gondwana
-
Chase Whitener
-
Christopher J. Madsen
-
chromatic
-
Dan Book
-
Daniel Hedlund
-
Daniel Trizen
-
David E. Wheeler
-
DAVIDRW
-
David Steinbrunner
-
Dorian Taylor
-
Eric Wastl
-
Father Chrysostomos
-
Felipe Gasper
-
FWILES
-
Galen Huntington
-
Gavin Peters
-
Graeme Thompson
-
Graham Knop
-
Håkon Hægland
-
Hans-H. Froehlich
-
Ian Kilgore
-
Jacob J
-
Jakub Wilk
-
jefflee
-
Jerome Eteve
-
john9art
-
jonasbn
-
Julien Fiegehenn
-
Karen Etheridge
-
Lars Dɪᴇᴄᴋᴏᴡ 迪拉斯
-
Mark Overmeer
-
Mark Stosberg
-
Martin H. Sluka
-
Matthew Chae
-
Max Maischein
-
Michael Schout
-
Michal Josef Špaček
-
Mickey Nasriachi
-
Mike Schilli
-
murphy
-
nanto_vi, TOYAMA Nao
-
Olaf Alders
-
Olivier Mengué
-
Ondrej Hanak
-
openstrike
-
Peter Rabbitson
-
phrstbrn
-
Robert Rothenberg
-
Robert Stone
-
Rolf Grossmann
-
ruff
-
sasao
-
Saturday Walkers Club
-
Sean M. Burke
-
Slaven Rezic
-
Spiros Denaxas
-
Steve Hay
-
Tatsuhiko Miyagawa
-
Theo van Hoesel
-
Tigran
-
Tobias Leich
-
Todd Lipcon
-
tokuhirom
-
Tom Hukins
-
Tony Finch
-
Toru Yamaguchi
-
tzccinct
- uid39246 <uid39246>
-
Ville Skyttä
-
Vít Strádal
-
William Storey
-
Yuri Karaban
-
Zakariyya Mughal
-
Zefram
- Dependencies
- Carp
- Compress::Raw::Zlib
- Encode
- Encode::Locale
- Exporter
- File::Spec
- HTTP::Date
- IO::Compress::Bzip2
- IO::Compress::Deflate
- IO::Compress::Gzip
- IO::HTML
- IO::Uncompress::Bunzip2
- IO::Uncompress::Gunzip
- IO::Uncompress::Inflate
- IO::Uncompress::RawInflate
- LWP::MediaTypes
- MIME::Base64
- MIME::QuotedPrint
- URI
- base
- strict
- warnings
- Reverse dependencies
- CPAN Testers List
- Dependency graph
NAME
HTTP::Headers::Util - Header value parsing utility functions
VERSION
version 6.37
SYNOPSIS
use HTTP::Headers::Util qw(split_header_words); @values = split_header_words($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:
- 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 @header_values 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*<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
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
undef
. Syntactically incorrect headers will not necessarily be parsed as you would want.This is easier to describe with some examples:
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\\""');
will return
[foo=>'bar', port=>'80,81', discard=> undef], [bar=>'baz' ] ['text/html' => undef, charset => 'iso-8859-1'] [basic => undef, realm => "\"foo\\bar\""]
If you don't want the function to convert tokens and attribute keys to lower case you can call it as
_split_header_words
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:
join_header_words(["text/plain" => undef, charset => "iso-8859/1"]); join_header_words("text/plain" => undef, charset => "iso-8859/1");
will both return the string:
text/plain; charset="iso-8859/1"
AUTHOR
Gisle Aas <gisle@activestate.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 1994 by Gisle Aas.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
Module Install Instructions
To install HTTP::Message, copy and paste the appropriate command in to your terminal.
cpanm HTTP::Message
perl -MCPAN -e shell install HTTP::Message
For more information on module installation, please visit the detailed CPAN module installation guide.