Difference between revisions of "Ns respond"

From AOLserver Wiki
Jump to navigation Jump to search
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
ns_respond
+
'''NAME'''
Overview
+
: ns_respond - Build a complete response
  
Build a complete response
+
'''SYNOPSIS'''
Syntax
+
: '''ns_respond''' ''?-status status? ?-type type? ?-string string | -file file | -fileid fileid? ?-length length? ?-headers setId?''
  
ns_respond ?-status status? ?-type type?
+
'''DESCRIPTION'''
  
{?-string string? | ?-file file? | ?-fileid fileid? }
+
: 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.
  
?-length length? ?-headers setId?
+
* -status status
Description
+
: The HTTP status code. Default 200.
  
ns_respond builds a complete response for the client with all of the specified information in the header.
+
* -type mimetype
Example
+
: The mime-type of the response body. Default */*.  
  
Using ns_respond, it's easy to do an HTTP redirect:
+
* -headers setid
 +
: A set of headers which will replace any pending headers for the response.
  
    set headers [ns_set new myheaders]
+
* -string body
    ns_set put $headers location http://www.aolserver.com
+
: 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.
    ns_respond -status 302 -type text/plain \
+
 
    -string "redirection" -headers $headers
+
* -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 <nowiki>http://www.aolserver.com</nowiki>
 +
ns_respond -status 302 -type text/plain \
 +
-string "redirection" -headers $headers

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