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


version 0.07


  use HTTP::Headers::ActionPack;

  my $n = HTTP::Headers::ActionPack->new->get_content_negotiator;

  # matches text/html; charset="iso8859-1"
      ["text/html", "text/html;charset=iso8859-1" ],
      "text/html;charset=iso8859-1, application/xml"

  # matches en-US
      ['en-US', 'es'],
      "da, en-gb;q=0.8, en;q=0.7"

  # matches US-ASCII
      [ "UTF-8", "US-ASCII" ],
      "US-ASCII, UTF-8"

  # matches gzip
      [ "gzip", "identity" },
      "gzip, identity;q=0.7"


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.


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.


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.


Stevan Little <>


  • Andrew Nelson <>

  • Dave Rolsky <>

  • Florian Ragwitz <>

  • Jesse Luehrs <>

  • Karen Etheridge <>


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.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 271:

Unknown directive: =head