Difference between revisions of "Ns startcontent"

From AOLserver Wiki
Jump to navigation Jump to search
Line 3: Line 3:
 
'''NAME'''
 
'''NAME'''
  
: ns_startcontent - Set connection to streaming state for streaming content via ns_write
+
: ns_startcontent - Configures connection for encoding non-binary content to be returned with ns_write
  
 
'''SYNOPSIS'''
 
'''SYNOPSIS'''
  
: '''ns_startcontent''' ''?-type content_type_and_encoding?''
+
: '''ns_startcontent''' ''?-type content_type_and_charset'' | -charset charset?''
  
 
'''DESCRIPTION'''
 
'''DESCRIPTION'''
  
: This command is used to set the current connection to streaming state, provides the appropriate encoding and indicates that the content part of the request is following. The content part is typically written via ns_write.
+
: This command is used to set the appropriate encoding prior to returning the content part of the response via [[ns_write]].
  
 
'''EXAMPLES'''
 
'''EXAMPLES'''
 +
: From [http://dqd.com/~mayoff/encoding-doc.html Character_Encoding_in_AOLserver]:
 +
# Assume japanesetext.html_sj is stored in Shift-JIS encoding.
 +
set fd [open japanesetext.html_sj r]
 +
fconfigure $fd -encoding shiftjis
 +
set html [read $fd [file size japanesetext.html_sj]]
 +
close $fd
  
: ns_startcontent -type "text/html; charset=[ns_config ns/parameters OutputCharset iso-8859-1]"
+
set charset [ns_choosecharset -preference {utf-8 shift-jis euc-jp iso-2022-jp}]
 +
set type "text/html; charset=$charset"
 +
ns_write "HTTP/1.0 200 OK
 +
Content-Type: $type
 +
\n"
 +
ns_startcontent -type $type
 +
ns_write $html
 +
 
 +
'''NOTES'''
  
 
'''SEE ALSO'''
 
'''SEE ALSO'''
  
 
: [[ns_write]], [[ns_config]]
 
: [[ns_write]], [[ns_config]]

Revision as of 04:20, 11 October 2009

<manpage>ns_startcontent</manpage>

NAME

ns_startcontent - Configures connection for encoding non-binary content to be returned with ns_write

SYNOPSIS

ns_startcontent ?-type content_type_and_charset | -charset charset?

DESCRIPTION

This command is used to set the appropriate encoding prior to returning the content part of the response via ns_write.

EXAMPLES

From Character_Encoding_in_AOLserver:
# Assume japanesetext.html_sj is stored in Shift-JIS encoding.
set fd [open japanesetext.html_sj r]
fconfigure $fd -encoding shiftjis
set html [read $fd [file size japanesetext.html_sj]]
close $fd
set charset [ns_choosecharset -preference {utf-8 shift-jis euc-jp iso-2022-jp}]
set type "text/html; charset=$charset"
ns_write "HTTP/1.0 200 OK
Content-Type: $type
\n"
ns_startcontent -type $type
ns_write $html

NOTES

SEE ALSO

ns_write, ns_config