Class response
Helpers for the HTTP response.
Defined in: <global\response.js>.
| Constructor Attributes | Constructor Name and Description |
|---|---|
|
response()
|
| Method Attributes | Method Name and Description |
|---|---|
| <static> |
response.addHeader(name, value)
Adds the name,value pair to the headers.
|
| <static> |
response.deleteCookie(name)
Tells the client to delete the cookie of the given name (by setting
its expiration time to zero).
|
| <static> |
response.forbid()
Halts the program immediately and returns 403 Forbidden error to the user.
|
| <static> |
response.notFound()
Halts the program immediately and returns a 404 not found error to the user.
|
| <static> |
response.redirect(path)
Halts the program immediately and sends an HTTP redirect response (302),
redirecting to the given path (relative or absolute).
|
| <static> |
response.setCacheable(cacheable)
Tells the client to cache the page.
|
| <static> |
response.setContentType(contentType)
Sets the Content-Type header of the response.
|
| <static> |
response.setCookie(cookieObject)
Set a cookie in the response.
|
| <static> |
response.setHeader(name, value)
Sets any header of the HTTP response.
|
| <static> |
response.setStatusCode(newCode)
Sets the status code in the HTTP response.
|
| <static> |
response.stop(renderCurrentPage)
Halts the program immediately, optionally printing the page so far.
|
| <static> |
response.write(data)
Low-level hook for writing raw data to the response.
|
| <static> |
response.writeBytes(data)
Low-level hook for writing raw byte data to the response.
|
Method Detail
<static>
response.addHeader(name, value)
Adds the name,value pair to the headers. Useful for headers that are
allowed to repeat, such as Set-Cookie.
- Parameters:
- {string} name
- {string} value
<static>
response.deleteCookie(name)
Tells the client to delete the cookie of the given name (by setting
its expiration time to zero).
- Parameters:
- {string} name
- The name of the cookie to delete.
<static>
response.forbid()
Halts the program immediately and returns 403 Forbidden error to the user.
<static>
response.notFound()
Halts the program immediately and returns a 404 not found error to the user.
<static>
response.redirect(path)
Halts the program immediately and sends an HTTP redirect response (302),
redirecting to the given path (relative or absolute).
- Parameters:
- {string} path
- The new path
<static>
response.setCacheable(cacheable)
Tells the client to cache the page. By default, clients are told to
not never cache pages. (To send no caching-related headers at all, pass
undefined.)
- Parameters:
- {boolean} cacheable
<static>
response.setContentType(contentType)
Sets the Content-Type header of the response. If the content-type includes
a charset, that charset is used to send the response.
- Parameters:
- {string} contentType
- the new content-type
<static>
response.setCookie(cookieObject)
Set a cookie in the response.
response.setCookie({
name: "SessionID",
value: "25",
secure: true,
expires: 14 // 14 days
});
- Parameters:
- {object} cookieObject
- This may contain any of the following:
- name (required): The name of the cookie
- value (required): The value of the cookie. (Note: this value will be escaped).
- expires (optional): If an integer, means number of days until it expires; if a Date object, means exact date on which to expire.
- domain (optional): The cookie domain
- path (optional): To restrict the cookie to a specific path.
- secure (optional): Whether this cookie should only be sent securely.
<static>
response.setHeader(name, value)
Sets any header of the HTTP response.
response.setHeader('Cache-Control', 'no-cache');
- Parameters:
- {string} name
- {string} value
<static>
response.setStatusCode(newCode)
Sets the status code in the HTTP response.
- Parameters:
- {number} newCode
<static>
response.stop(renderCurrentPage)
Halts the program immediately, optionally printing the page so far.
- Parameters:
- {boolean} renderCurrentPage
- if false, an empty page will be rendered, otherwise calls to print() so far will be displayed. Either way, no more code will be executed.
<static>
response.write(data)
Low-level hook for writing raw data to the response.
- Parameters:
- {string} data
- will be written, verbatim, to the HTTP resonse.
<static>
response.writeBytes(data)
Low-level hook for writing raw byte data to the response. Especially
useful for writing the result of a
wget of image data,
or writing an uploaded file.
- Parameters:
- {string} data
- will be written, verbatim, to the HTTP resonse.