logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

HTTP::Headers::ActionPack::ContentNegotiation - A class to handle content negotiation

Author

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>

Description

       This class provides a set of methods used for content negotiation. It makes full use of all the header
       objects, such as HTTP::Headers::ActionPack::MediaType, HTTP::Headers::ActionPack::MediaTypeList and
       HTTP::Headers::ActionPack::PriorityList.

       Content negotiation is a tricky business, it needs to account for such things as the quality rating,
       order of elements (both in the header and in the list of provided items) and in the case of media types
       it gets even messier. This module does it's best to figure things out and do what is expected on it. We
       have included a number of examples from the RFC documents in our test suite as well.

Methods

       "choose_media_type ( $provided, $header )"
           Given  an  ARRAY  ref  of  media  type strings and an HTTP header, this will return the appropriately
           matching HTTP::Headers::ActionPack::MediaType instance.

       "choose_language ( $provided, $header )"
           Given a list of language codes and an HTTP header value, this will  attempt  to  negotiate  the  best
           language match. It will return the language string that best matched.

       "choose_charset ( $provided, $header )"
           Given  a  list  of  charset  names  and an HTTP header value, this will attempt to negotiate the best
           charset match. It will return the name of the charset that best matched.

       "choose_encoding ( $provided, $header )"
           Given a list of encoding names and an HTTP header value, this will  attempt  to  negotiate  the  best
           encoding match. It will return the name of the encoding which best matched.

Name

       HTTP::Headers::ActionPack::ContentNegotiation - A class to handle content negotiation

See Also

       HTTP::Negotiate

       There  is  nothing wrong with this module, however it attempts to answer all the negotiation questions at
       once, whereas this module allows you to do it one thing at a time.

Synopsis

         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"
         );

Version

       version 0.09

See Also