HTTP::...tiation(3pm)
π HTTP::Headers::ActionPack::ContentNegotiation β the manual, but make it cute π
okay bestie, so this is the page for HTTP::Headers::ActionPack::ContentNegotiation(3pm), and honestly? it's giving "quiet little module that does an unhinged amount of work behind the scenes." no cap. let's get into it. π¦
β¨ NAME β¨
HTTP::Headers::ActionPack::ContentNegotiation β a whole class dedicated to handling content negotiation. yes, that content negotiation. the "which of these does the browser actually want" situation. π
πΈ VERSION πΈ
version 0.09 β she's a lil vintage, we love her for it.
π SYNOPSIS π
here's the vibe, copy-paste ready:
use HTTP::Headers::ActionPack;
my $n = HTTP::Headers::ActionPack->new->get_content_negotiator;
# matches text/html; charset="iso8859-1"
$n->choose_media_type(
["text/html", "text/html;charset=iso8859-1" ],
"text/html;charset=iso8859-1, application/xml"
);
# matches en-US
$n->choose_language(
['en-US', 'es'],
"da, en-gb;q=0.8, en;q=0.7"
);
# matches US-ASCII
$n->choose_charset(
[ "UTF-8", "US-ASCII" ],
"US-ASCII, UTF-8"
);
# matches gzip
$n->choose_encoding(
[ "gzip", "identity" },
"gzip, identity;q=0.7"
);
and yes, that last one has a curly brace where a square bracket should be. that's in the original, bestie. we do not touch the artifact. πΊβ¨
π DESCRIPTION π
so this class hands you a lil toolkit of methods for content negotiation. it goes full main-character with all the header objects β it makes full use of HTTP::Headers::ActionPack::MediaType, HTTP::Headers::ActionPack::MediaTypeList and HTTP::Headers::ActionPack::PriorityList. obsessed. π₯
ngl, content negotiation is a tricky business. like, it has to account for the quality rating, the order of elements (both in the header and in the list of provided items), and for media types specifically it gets even messier. this module does its best to figure things out and do what's expected of it. and as a lil flex, they included a bunch of examples from the RFC documents in the test suite too. periodt. π
π§ METHODS π§
choose_media_type ( $provided, $header )β you hand it an ARRAY ref full of media type strings plus an HTTP header, and it returns the matchingHTTP::Headers::ActionPack::MediaTypeinstance that fits best. slay. β¨choose_language ( $provided, $header )β give it a list of language codes and an HTTP header value, and it'll try to negotiate the best language match for you. it returns the language string that matched best. πchoose_charset ( $provided, $header )β pass in a list of charset names and an HTTP header value, and it attempts to negotiate the best charset match. it returns the name of the charset that best matched. πchoose_encoding ( $provided, $header )β hand over a list of encoding names and an HTTP header value, and it'll attempt to negotiate the best encoding match, returning the name of the encoding which best matched. π«Ά
π SEE ALSO π
HTTP::Negotiate
and okay, real talk: there is nothing wrong with HTTP::Negotiate. none. zero. she's fine. the difference is that she attempts to answer all the negotiation questions at once, whereas this module lets you do it one thing at a time. choose-your-own-adventure energy. iykyk. π
π AUTHOR π
Stevan Little <stevan.little@iinteractive.com> β the founder of this whole era.
π CONTRIBUTORS π
- Andrew Nelson
<anelson@cpan.org> - Dave Rolsky
<autarch@urth.org> - Florian Ragwitz
<rafl@debian.org> - Jesse Luehrs
<doy@tozt.net> - Karen Etheridge
<ether@cpan.org>
the whole group chat showed up to help. we love a collaborative moment. ππ
πΈ COPYRIGHT AND LICENSE πΈ
This software is copyright (c) 2012 by Infinity Interactive, Inc..
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
and that's the whole page, bestie!! π
β¨ this lil doc was served up by perl v5.34.0, dated 2022-06-14, under the manual name HTTP::...tiation(3pm). no cap, she's iconic. go negotiate something. ππ¦π
π¦ where this page comes from
- debian bookworm: libhttp-headers-actionpack-perl 0.09-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libhttp-headers-actionpack-perl 0.09-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms