Difference between revisions of "Ns choosecharset"

From AOLserver Wiki
Jump to navigation Jump to search
(imported from WiKit id 532)
 
Line 14: Line 14:
  
 
: Performs an analysis of the request's accepted charsets, against either the given charset list, or the configured default preferred character set list (ns/parameters/PreferredCharsets).
 
: Performs an analysis of the request's accepted charsets, against either the given charset list, or the configured default preferred character set list (ns/parameters/PreferredCharsets).
 +
 +
: From [http://dqd.com/~mayoff/encoding-doc.html Character Encoding in AOLserver]:
 +
: The client may specify what charsets in accepts by sending an Accept-Charset header in its HTTP request. If the Accept-Charset header is missing, then the client is assumed to accept any charset. The ns_choosecharset command will return the best charset to use, taking into account the Accept-Charset header and the charsets supported by AOLserver.
 +
 +
:The ns_choosecharset algorithm:
 +
# Set preferred-charsets to the list of charsets specified by the -preference flag. If that flag was not given, use the config parameter ns/parameters/PreferredCharsets. If the config parameter is missing, use {utf-8 iso-8859-1}. The list order is significant.
 +
# Set acceptable-charsets to the intersection of the Accept-Charset charsets and the charsets supported by AOLserver.
 +
# If acceptable-charsets is empty, return the charset specified by config parameter ns/parameters/DefaultCharset, or iso-8859-1 by default.
 +
# Choose the first charset from preferred-charsets that also appears in acceptable-charsets. Return that charset.
 +
# If no charset in preferred-charsets also appears in acceptable-charsets, then choose the first charset listed in Accept-Charsets that also appears in acceptable-charsets. Return that charset.
 +
 +
(Note: the last step will always return a charset because acceptable-charsets can only contain charsets listed by Accept-Charsets.)
 +
 +
  
 
'''EXAMPLES'''
 
'''EXAMPLES'''

Revision as of 04:51, 11 October 2009

Man page: http://aolserver.com/docs/tcl/ns_choosecharset.html


NAME

ns_choosecharset - Return the name of the most appropriate charset for the request

SYNOPSIS

ns_choosecharset ?-preference charset-list?

DESCRIPTION

Performs an analysis of the request's accepted charsets, against either the given charset list, or the configured default preferred character set list (ns/parameters/PreferredCharsets).
From Character Encoding in AOLserver:
The client may specify what charsets in accepts by sending an Accept-Charset header in its HTTP request. If the Accept-Charset header is missing, then the client is assumed to accept any charset. The ns_choosecharset command will return the best charset to use, taking into account the Accept-Charset header and the charsets supported by AOLserver.
The ns_choosecharset algorithm:
  1. Set preferred-charsets to the list of charsets specified by the -preference flag. If that flag was not given, use the config parameter ns/parameters/PreferredCharsets. If the config parameter is missing, use {utf-8 iso-8859-1}. The list order is significant.
  2. Set acceptable-charsets to the intersection of the Accept-Charset charsets and the charsets supported by AOLserver.
  3. If acceptable-charsets is empty, return the charset specified by config parameter ns/parameters/DefaultCharset, or iso-8859-1 by default.
  4. Choose the first charset from preferred-charsets that also appears in acceptable-charsets. Return that charset.
  5. If no charset in preferred-charsets also appears in acceptable-charsets, then choose the first charset listed in Accept-Charsets that also appears in acceptable-charsets. Return that charset.

(Note: the last step will always return a charset because acceptable-charsets can only contain charsets listed by Accept-Charsets.)


EXAMPLES

   % ns_choosecharset
   iso-8859-1
   % ns_choosecharset -preference list cp-1258 macromania
   cp-1258

SEE ALSO

ns_charsets

Category Documentation - Category Core Tcl API