1HTTP::Headers::ActionPaUcske:r:CCoonnttHerTniTtbPNu:et:geHodetaiPdaeetrrilso:nD:(oA3cc)utmieonntPaatciko:n:ContentNegotiation(3)
2
3
4
6 HTTP::Headers::ActionPack::ContentNegotiation - A class to handle
7 content negotiation
8
10 version 0.09
11
13 use HTTP::Headers::ActionPack;
14
15 my $n = HTTP::Headers::ActionPack->new->get_content_negotiator;
16
17 # matches text/html; charset="iso8859-1"
18 $n->choose_media_type(
19 ["text/html", "text/html;charset=iso8859-1" ],
20 "text/html;charset=iso8859-1, application/xml"
21 );
22
23 # matches en-US
24 $n->choose_language(
25 ['en-US', 'es'],
26 "da, en-gb;q=0.8, en;q=0.7"
27 );
28
29 # matches US-ASCII
30 $n->choose_charset(
31 [ "UTF-8", "US-ASCII" ],
32 "US-ASCII, UTF-8"
33 );
34
35 # matches gzip
36 $n->choose_encoding(
37 [ "gzip", "identity" },
38 "gzip, identity;q=0.7"
39 );
40
42 This class provides a set of methods used for content negotiation. It
43 makes full use of all the header objects, such as
44 HTTP::Headers::ActionPack::MediaType,
45 HTTP::Headers::ActionPack::MediaTypeList and
46 HTTP::Headers::ActionPack::PriorityList.
47
48 Content negotiation is a tricky business, it needs to account for such
49 things as the quality rating, order of elements (both in the header and
50 in the list of provided items) and in the case of media types it gets
51 even messier. This module does it's best to figure things out and do
52 what is expected on it. We have included a number of examples from the
53 RFC documents in our test suite as well.
54
56 "choose_media_type ( $provided, $header )"
57 Given an ARRAY ref of media type strings and an HTTP header, this
58 will return the appropriately matching
59 HTTP::Headers::ActionPack::MediaType instance.
60
61 "choose_language ( $provided, $header )"
62 Given a list of language codes and an HTTP header value, this will
63 attempt to negotiate the best language match. It will return the
64 language string that best matched.
65
66 "choose_charset ( $provided, $header )"
67 Given a list of charset names and an HTTP header value, this will
68 attempt to negotiate the best charset match. It will return the
69 name of the charset that best matched.
70
71 "choose_encoding ( $provided, $header )"
72 Given a list of encoding names and an HTTP header value, this will
73 attempt to negotiate the best encoding match. It will return the
74 name of the encoding which best matched.
75
77 HTTP::Negotiate
78
79 There is nothing wrong with this module, however it attempts to answer
80 all the negotiation questions at once, whereas this module allows you
81 to do it one thing at a time.
82
84 Stevan Little <stevan.little@iinteractive.com>
85
87 • Andrew Nelson <anelson@cpan.org>
88
89 • Dave Rolsky <autarch@urth.org>
90
91 • Florian Ragwitz <rafl@debian.org>
92
93 • Jesse Luehrs <doy@tozt.net>
94
95 • Karen Etheridge <ether@cpan.org>
96
98 This software is copyright (c) 2012 by Infinity Interactive, Inc..
99
100 This is free software; you can redistribute it and/or modify it under
101 the same terms as the Perl 5 programming language system itself.
102
103
104
105perl v5.36.0 HTTP2:0:2H2e-a0d7e-r2s2::ActionPack::ContentNegotiation(3)