5.9Object Reply

Reflects the reply that this script has sent (or will send).

Object Reply

This object contains the header that the system is going to send back to the remote client as soon as the first output (through the ">" operator or through print functions) is performed. If output has already been performed, then the header becomes read-only, and the Reply.sent field becomes true.

Falcon template files willing to change the output header should escape to Falcon immediately, giving the escape sequence as their very first character, as unescaped text is immediately sent to the upstream server.

A suitable default header with "+200 OK", no cache pragmas and text/html in utf-8 encoding is provided by default.

Properties
reason Descriptive http reply reason.
sent True when the header has been delivered, false if the header is still unsent.
status Numeric HTTP reply code.
Methods
clearCookieRemove given cookie.
commitSends immediately the header and pending data.
ctypeHelper creating a Content-Type header.
getHeaderRetrieves the value of a given header.
getHeadersreturns the list of headers that will be sent (or have been sent).
redirectHelper creating a Refresh (redirection) header.
setCookiesets a cookie that will be received next time that a script is called.
setHeaderAdds or remove a reply header.

Properties

reason

Descriptive http reply reason.

Descriptive http reply reason. In the "+200 OK" standard reply, it's the "OK" part.

sent

True when the header has been delivered, false if the header is still unsent.

True when the header has been delivered, false if the header is still unsent.

status

Numeric HTTP reply code.

Numeric HTTP reply code. For example, 200 (meaning OK).

Methods

clearCookie

Remove given cookie.

Reply.clearCookie( name )
name The cookie to be removed.

This function explicitly tries to clear the cookie from the remote client cache. The cookie value is not removed from the Request.cookies array.

commit

Sends immediately the header and pending data.

Reply.commit()

Usually, the integration module sends the header upstream at a reasonable moment, but some scripts may prefer to send the header sooner; in example, this is useful if the script is just generating a reply that consists in an HTTP header without data, or to start a keep-alive HTTP/1.1 conversation.

ctype

Helper creating a Content-Type header.

Reply.ctype( type, [subtype],[charset] )
type Main MIME type of the data that shall be sent to output.
subtype MIME Subtype that shall be sent to the output.
charset MIME Charset encoding of the output (if text).

Creates a Content-Type: <type>/<subtype>; charset=<charset> field in the headers. It's just a shortcut.

Note: Many functions in the module suppose that the output will be utf-8.

getHeader

Retrieves the value of a given header.

Reply.getHeader( name )
name The name of the header to be queried.
ReturnIf the header is set, its value as a string; false otherwise.

The header name is automatically capitalized at the beginning and after each '-' symbol.

Note: Pay attention to the fact that the maps in which headers are stored are case-sensitive.

getHeaders

returns the list of headers that will be sent (or have been sent).

Reply.getHeaders()
ReturnA dictionary of strings containing all the headers prepared for being sent.

This method returns a map containing all the headers that the WOPI system is going to send, or that have been sent if output is already started.

The map is a snapshot of the current status of the Reply. Headers can be manipulated only through Reply.setHeader. Any change to this structure won't be reflected on the actual reply headers, and similarly, any change in the Reply headers will not be reflected into this value.

redirect

Helper creating a Refresh (redirection) header.

Reply.redirect( [uri],[timeout] )
uri Where to redirect the page.
timeout Number of seconds before refresh takes place.

This function creates a well-formed "Refresh" header in the reply, which can:

Note: As this method mangles the output headers, it must be called before any output is sent to the client. Otherwise, it will be ignored.

setCookie

sets a cookie that will be received next time that a script is called.

Reply.setCookie( name, [value],[expires],[path],[domain],[secure],[httpOnly] )
name Name of the Cookie or complete cookie specification in a dictionary.
value Value for the cookie (eventually truned into a string).
expires Expiration date (a TimeStamp or an ISO or RFC2822 formatted string), or maximum life in seconds (an integer).
path Cookie path validity
domain Domain for which the cookie is valid.
secure True to specify that the cookie can be sent only in https.
httpOnly If true, this cookie will be invisible to client side scripts, and will be only sent to the server.

This facility allows to store variables on the remote system (usually a web browser), which will send them back each time it connects again.

The cookies sent through this function will be received in the cookies member of subquesent call to this or other scripts.

Parameters to be left blank can be skipped using nil; however, it may be useful to use the named parameter convention.

For example:


      Reply.setCookie( "cookie1", "value1", nil, nil, ".mydomain.com", false, true )

      // but probably better
      Reply.setCookie(
         name|"cookie1",
         value|"value1",
         domain|".mydomain.com",
         httpOnly|true
         )

Only the name parameter is mandatory.

Note: Cookies must be set before output is sent to the upstream server.

setHeader

Adds or remove a reply header.

Reply.setHeader( name, [value] )
name The header to be created or removed.
value If given and not nil, the value to be stored in the header; if not given, or nil, the header will be removed.

This sets the given header to the required value. The value parameter can be of any type; if it's not a string, a standard conversion to string will be attempted.

In case value is not given or is nil, the header is removed.

The header name is automatically capitalized at the beginning and after each '-' symbol.

Note: Pay attention to the fact that the maps in which headers are stored are case-sensitive. A case mismatch may cause an undesired duplication of the header.

Made with http://www.falconpl.org