Difference between revisions of "Ns respond"

From AOLserver Wiki
Jump to navigation Jump to search
(wiki-formatted the page)
 
Line 3: Line 3:
  
 
'''SYNOPSIS'''
 
'''SYNOPSIS'''
: '''ns_respond''' ''?-status status? ?-type type? {?-string string? | ?-file file? | ?-fileid fileid? } ?-length length? ?-headers setId?''
+
: '''ns_respond''' ''?-status status? ?-type type? ?-string string | -file file | -fileid fileid? ?-length length? ?-headers setId?''
  
 
'''DESCRIPTION'''
 
'''DESCRIPTION'''
  
: ns_respond builds a complete response for the client with all of the specified information in the header.
+
: ns_respond returns a complete response to the client using exactly one of -string, -file or -fileid as the body.  After the command completes the connection is returned to the driver thread to be closed or monitored for keep-alive and the calling connection thread continues to execute code.  Just like with ns_return, all the normal compression, encoding, chunking, etc. processing applies, unless otherwise noted below.
 +
 
 +
* -status status
 +
: The HTTP status code. Default 200.
 +
 
 +
* -type mimetype
 +
: The mime-type of the response body. Default */*.
 +
 
 +
* -headers setid
 +
: A set of headers which will replace any pending headers for the response.
 +
 
 +
* -string body
 +
: The Tcl string to send as the response body. The body may be encoded into an apprpriate character set if required by the client and server settings.
 +
 
 +
* -file filepath
 +
: The file identified by the given pathname will be sent as the response body. No character set conversion will be done.
 +
 
 +
* -fileid channel
 +
: length bytes of the given channel will be used as the response body. No character set conversion will be done.
 +
 
 +
* -length length
 +
: Specifies the number of bytes to send from the channel. Required if using -fileid
 +
 
  
 
'''EXAMPLE'''
 
'''EXAMPLE'''

Latest revision as of 06:30, 11 October 2009

NAME

ns_respond - Build a complete response

SYNOPSIS

ns_respond ?-status status? ?-type type? ?-string string | -file file | -fileid fileid? ?-length length? ?-headers setId?

DESCRIPTION

ns_respond returns a complete response to the client using exactly one of -string, -file or -fileid as the body. After the command completes the connection is returned to the driver thread to be closed or monitored for keep-alive and the calling connection thread continues to execute code. Just like with ns_return, all the normal compression, encoding, chunking, etc. processing applies, unless otherwise noted below.
  • -status status
The HTTP status code. Default 200.
  • -type mimetype
The mime-type of the response body. Default */*.
  • -headers setid
A set of headers which will replace any pending headers for the response.
  • -string body
The Tcl string to send as the response body. The body may be encoded into an apprpriate character set if required by the client and server settings.
  • -file filepath
The file identified by the given pathname will be sent as the response body. No character set conversion will be done.
  • -fileid channel
length bytes of the given channel will be used as the response body. No character set conversion will be done.
  • -length length
Specifies the number of bytes to send from the channel. Required if using -fileid


EXAMPLE

Using ns_respond, it's easy to do an HTTP redirect:
set headers [ns_set new myheaders]
ns_set put $headers location http://www.aolserver.com
ns_respond -status 302 -type text/plain \
	-string "redirection" -headers $headers