Ns choosecharset

From AOLserver Wiki
Jump to navigation Jump to search

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


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


ns_choosecharset ?-preference charset-list?


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.)


   % ns_choosecharset
   % ns_choosecharset -preference list cp-1258 macromania



Category Documentation - Category Core Tcl API