Hello,

there are a few stumbling blocks in choose() - see comments in the testcase.

Unfortunately I am not very fluent in Perl so I'm hesitating trying to 
fix these myself. Does anybody have time to look into the attached testcase?

Thanks,
Michael Hennecke

 ======================================================================
  Michael Hennecke      http://www.uni-karlsruhe.de/~Michael.Hennecke/ 
 ----------------------------------------------------------------------
  University of Karlsruhe          mailto:[EMAIL PROTECTED] 
  Computing Center                         Building 20.21  /  Room 210
  Zirkel 2  *  P.O. Box 69 80                 Phone: +49 721  608-4862 
  D-76128  Karlsruhe,  GERMANY                     Fax: +49 721  32550 
 ======================================================================
#!/usr/local/bin/perl -w
#
# @(#) $Id: negotiate.pl,v 1.2 2001/06/05 23:22:22 Administrator Exp $
#
#
# BUGS IN REVISION 1.7:
#
# * choose() is case-sensitive in the Lang field of the $variants although
#   RFC1766 requires that "All tags are to be treated as case insensitive"
# * choose() ignores uppercase Q as quality factor in HTTP_ACCEPT_LANGUAGE
#   Shouldn't it treat it case-insensitive?
# * choose() produces a -w warning in line 107 when DEBUG is true,
#   may be fixed with "$ct='' unless defined $ct;" before line 107
#
# NOT STRICTLY A BUG BUT *VERY* UNFORTUNATE IMPLEMENTATION IN REVISION 1.7:
#
# If the http-accept-language quality factor multiplied by
# the $variant quality factor are the same for a number of variants, 
# choose() prefers the variant that comes first in the $variants array, 
# not the variant that comes first in http-accept-language. 
# This is very unfortunate: 
# If the browser doesn't specify q (as is the case in many products today), 
# and all qs values in $variants are the same, then the user really
# expects that the order in their http-accept-language list is followed, 
# not some arbitrary order in which the variants appear in $variants.
# In particular, this is how Apache's content negotiation works.
#
# In the testcase below, var-de and var-en both end up with Q=1.000, 
# de is first in http-accept-language, but choose() returns var-en
# because var-en comes first in $variants
#

use strict;
use HTTP::Negotiate;

print "\nTesting HTTP::Negotiate ", &HTTP::Negotiate::Version, " ...\n\n";

$HTTP::Negotiate::DEBUG=1;

$ENV{HTTP_ACCEPT_LANGUAGE}='DE,en,fr;Q=0.5,es;q=0.1';

print "HTTP_ACCEPT_LANGUAGE is set to $ENV{HTTP_ACCEPT_LANGUAGE}\n\n";

my $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],
 ];

my $choice = &HTTP::Negotiate::choose($variants);

print "\nchoose() has chosen $choice\n";

Reply via email to