set_encoding (private, deprecated)

 set_encoding [ -text_translation text_translation ] content_type \
    channel

Defined in packages/acs-tcl/tcl/deprecated-procs.tcl

Deprecated. Invoking this procedure generates a warning.

The ad_http* and util_http* machineries depend on the AOLserver/NaviServer socket I/O layer provided by [ns_sockopen]. This proc allows you to request Tcl encoding filtering for ns_sockopen channels (i.e., the read and write channels return by [ns_sockopen]), to be applied right before performing socket I/O operations (i.e., reads).

The major task is to resolve the corresponding Tcl encoding (e.g.: ascii) for a given IANA/MIME charset name (or alias; e.g.: US-ASCII); the main resolution scheme is implemented by [ns_encodingfortype] which is available bother under AOLserver and NaviServer (see tcl/charsets.tcl). The mappings between Tcl encoding names (as shown by [encoding names]) and IANA/MIME charset names (i.e., names and aliases in the sense of IANA's character sets registry) is provided by:

  • A static, built-in correspondence map: see nsd/encoding.c
  • An extensible correspondence map (i.e., the ns/charsets section in config.tcl).

[ns_encodingfortype] introduces several levels of precedence when resolving the actual IANA/MIME charset and the corresponding Tcl encoding to use:

  1. The "content_type" string contains a charset specification, e.g.: "text/xml; charset=UTF-8". This spec fragment takes the highest precedence.
  2. The "content_type" string points to a "text/*" media subtype, but does not specify a charset (e.g., "text/xml"). In this case, the charset defined by ns/parameters/OutputCharset (see config.tcl) applies. If this parameter is missing, the default is "iso-8859-1" (see tcl/charsets.tcl; this follows from RFC 2616 (HTTP 1.1); Section 3.7.1).
  3. If neither case 1 or case 2 become effective, the encoding is resolved to "binary".
  4. If [ns_encodingfortype] fails to resolve any Tcl encoding name (i.e., returns an empty string), the general fallback is "iso8859-1" for text/* media subtypes and "binary" for any other. This is the case in two situations:
    • Invalid IANA/MIME charsets: The name in the "charset" parameter of the content type spec is not a valid name or alias in IANA's character sets registry (a special variant would be an empty charset value, e.g. "text/plain; charset=")
    • Unknown IANA/MIME charsets: The name in the "charset" parameter of the content type spec does not match any known (= registered) IANA/MIME charset in the MIME/Tcl mappings.
References:

Switches:
-text_translation (optional, defaults to "auto binary")
Parameters:
content_type (required)
channel (required)
Author:
stefan.sobernig@wu.ac.at

Testcases:
No testcase defined.
Source code:
ad_log_deprecated proc set_encoding
    set trl [expr {[string match "text/*" $content_type] ? $text_translation : "binary"}]
    set enc [ns_encodingfortype $content_type]
    if {$enc eq ""} {
        set enc [expr {[string match "text/*" $content_type] ? "iso8859-1" : "binary"}]
        ns_log debug "--- Resolving a Tcl encoding for the CONTENT-TYPE '$content_type' failed; falling back to '$enc'."
    }
    fconfigure $channel -translation $trl -encoding $enc
XQL Not present:
PostgreSQL, Oracle
Generic XQL file:
packages/acs-tcl/tcl/deprecated-procs.xql

[ hide source ] | [ make this the default ]
Show another procedure: