Ns respond

From AOLserver Wiki
Jump to navigation Jump to search

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