Websh can send output to any Tcl channel and to global variables (web::put). Optionally, data is scanned for Tcl code before it is output to a channel (web::putx). Websh manages response objects that are related to Tcl channels and are identified using the name of the corresponding Tcl channel. Configuration is achieved with web::response.
web::response
web::response
?option
?
web::response
?subcommand
? args
Subcommands are -select, -set, -lappend, -names, -count, -unset, -reset, and -resetall Options are -sendheader, -httpresponse, and -bytessent.
Selects the default response object and sets and accesses properties of the response object, and returns the name of the response object.
channelName
channelName
as new response
object. If the channelName
is
prepended by a #, it refers to a global
variable named channelName
.
key
?value
?web::response -set Content-Type text/plain
.
key
key
?value
?web::response -set Status "400 Bad Request"
.
Example 10. web::response
% web::response stdout % web::response -select stderr stdout % web::response stderr % web::response -sendheader 1 % web::response -names Content-Type Generator % web::response Content-Type text/html % web::response -bytessent 0 % web::response -set Set-Cookie "my cookie that contains data" % web::put "Hello, world\n" Content-Type: text/html Set-Cookie: my cookie that contains data Generator: websh3.6.0 Hello, world %
web::put
?
?#?
channel
? text
Send output to a Tcl channel. No newline is added to
output. If
?channel
?
is ommitted, output is sent to the current default
channel. The default channel can be changed with
web::response -select
?#?channel
.
The optional hash ("#") denotes that output should be
sent to a global variable named
channel
instead of
a Tcl channel.
web::putx
?
?#?
channel
? text
Writes text to the specified channel. Code in
curly brackets is eval'd, unless the brackets are escaped by
"\". These markup characters '{...}' can be changed
to '<? ... ?>' with 'web::config putxmarkup tag'. The optional hash ("#") denotes that output should be sent to a global variable named channel
instead of a Tcl channel.
web::putxfile
?
?#?
channel
? file
?msg
?Like web::putx, but takes input from a file.
Returns 0 on success, 1 otherwise. If an error occurs, an
error message is written to msg. If only two
arguments are passed, then channel takes
precedence. The optional hash ("#") denotes that output should be sent to a global variable named channel
instead of a Tcl channel.