HTTP-Negotiate

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

       Source quality is measured by the content provider as representing
       the amount of degradation from the original source. For example, a
       picture in JPEG form would have a lower qs when translated to the XBM
       format, and much lower qs when translated to an ASCII-art
       representation. Note, however, that this is a function of the source
       - an original piece of ASCII-art may degrade in quality if it is
       captured in JPEG form. The qs values should be assigned to each
       variant by the content provider; if no qs value has been assigned,
       the default is generally "qs=1".

    content-type
       This is the media type of the variant. The media type does not
       include a charset attribute, but might contain other parameters.
       Examples are:

         text/html
         text/html;version=2.0
         text/plain
         image/gif
         image/jpg

lib/HTTP/Negotiate.pm  view on Meta::CPAN

	my $mbx = undef;
	# If no Accept field is given, then the value assigned is "q=1".
	# If at least one listed media range matches the variant's media
	# type, then the "q" parameter value assigned to the most specific
	# of those matched is used (e.g. "text/html;version=3.0" is more
	# specific than "text/html", which is more specific than "text/*",
	# which in turn is more specific than "*/*"). If not media range
	# in the provided Accept field matches the variant's media type,
	# then the value assigned is "q=0".
	if (exists $accept{'type'} && $ct) {
	    # First we clean up our content-type
	    $ct =~ s/\s+//g;
	    my $params = "";
	    $params = $1 if $ct =~ s/;(.*)//;
	    my($type, $subtype) = split("/", $ct, 2);
	    my %param = ();
	    for $param (split(/;/, $params)) {
		my($pk,$pv) = split(/=/, $param, 2);
		$param{$pk} = $pv;
	    }

lib/HTTP/Negotiate.pm  view on Meta::CPAN

	    ACCEPT_TYPE:
	    for $at (keys %{ $accept{'type'} }) {
		print "Consider $at...\n" if $DEBUG;
		my($at_type, $at_subtype) = split("/", $at, 2);
		# Is it a match on the type
		next if $at_type    ne '*' && $at_type    ne $type;
		next if $at_subtype ne '*' && $at_subtype ne $subtype;
		my $specificness = 0;
		$specificness++ if $at_type ne '*';
		$specificness++ if $at_subtype ne '*';
		# Let's see if content-type parameters also match
		while (($pk, $pv) = each %param) {
		    print "Check if $pk = $pv is true\n" if $DEBUG;
		    next unless exists $accept{'type'}{$at}{$pk};
		    next ACCEPT_TYPE
		      unless $accept{'type'}{$at}{$pk} eq $pv;
		    print "yes it is!!\n" if $DEBUG;
		    $specificness++;
		}
		print "Hurray, type match with specificness = $specificness\n"
		  if $DEBUG;

lib/HTTP/Negotiate.pm  view on Meta::CPAN

Source quality is measured by the content provider as representing the
amount of degradation from the original source.  For example, a
picture in JPEG form would have a lower qs when translated to the XBM
format, and much lower qs when translated to an ASCII-art
representation.  Note, however, that this is a function of the source
- an original piece of ASCII-art may degrade in quality if it is
captured in JPEG form.  The qs values should be assigned to each
variant by the content provider; if no qs value has been assigned, the
default is generally "qs=1".

=item content-type

This is the media type of the variant.  The media type does not
include a charset attribute, but might contain other parameters.
Examples are:

  text/html
  text/html;version=2.0
  text/plain
  image/gif
  image/jpg

t/negotiate.t  view on Meta::CPAN

expect(\@a, [['var2' => 0.25],
	     ['var1' => 0],
	     ['var3' => 0]
	    ]
);

$variants = [
  ['var-en', undef, 'text/html', undef, undef, 'en', undef],
  ['var-de', undef, 'text/html', undef, undef, 'de', undef],
  ['var-ES', undef, 'text/html', undef, undef, 'ES', undef],
  ['provoke-warning',  undef, undef, undef, undef, 'x-no-content-type', undef],
 ];

$HTTP::Negotiate::DEBUG=1;
$ENV{HTTP_ACCEPT_LANGUAGE}='DE,en,fr;Q=0.5,es;q=0.1';

$a = choose($variants);

ok($a, 'var-de');




( run in 2.742 seconds using v1.01-cache-2.11-cpan-524268b4103 )