.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "HTTP::Headers::ActionPack::ContentNegotiation 3pm" .TH HTTP::Headers::ActionPack::ContentNegotiation 3pm 2024-03-06 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME HTTP::Headers::ActionPack::ContentNegotiation \- A class to handle content negotiation .SH VERSION .IX Header "VERSION" version 0.09 .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& 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( \& [\*(Aqen\-US\*(Aq, \*(Aqes\*(Aq], \& "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" \& ); .Ve .SH DESCRIPTION .IX Header "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. .PP 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. .SH METHODS .IX Header "METHODS" .ie n .IP """choose_media_type ( $provided, $header )""" 4 .el .IP "\f(CWchoose_media_type ( $provided, $header )\fR" 4 .IX Item "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. .ie n .IP """choose_language ( $provided, $header )""" 4 .el .IP "\f(CWchoose_language ( $provided, $header )\fR" 4 .IX Item "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. .ie n .IP """choose_charset ( $provided, $header )""" 4 .el .IP "\f(CWchoose_charset ( $provided, $header )\fR" 4 .IX Item "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. .ie n .IP """choose_encoding ( $provided, $header )""" 4 .el .IP "\f(CWchoose_encoding ( $provided, $header )\fR" 4 .IX Item "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. .SH "SEE ALSO" .IX Header "SEE ALSO" HTTP::Negotiate .PP 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. .SH AUTHOR .IX Header "AUTHOR" Stevan Little .SH CONTRIBUTORS .IX Header "CONTRIBUTORS" .IP \(bu 4 Andrew Nelson .IP \(bu 4 Dave Rolsky .IP \(bu 4 Florian Ragwitz .IP \(bu 4 Jesse Luehrs .IP \(bu 4 Karen Etheridge .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2012 by Infinity Interactive, Inc.. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.