Sitevision Developer
Log in

Log in

response (res)

The res object is a representation of the HTTP-response.

Methods

res.send(response)

Sends a character response. Type will be text/html if not explicitly set.

res.json(response)

Sends a application/json-response.

res.set(name, value)

Sets a HTTP-header in the response. Returns this for chaining purposes.

res.type(type)

Sets the response Content-Type header. If type contains the “/” character, then it will be used as-is. Returns this for chaining purposes.

res.sendFile(file)

Sends a file as response. Uses best effort for content type matching if no type is explicitly set. File argument must be a Sitevision JCR-Node of type sv:file, sv:image or sv:temporaryFile . Byte array (byte[]), (java.io.File is also allowed for legacy reasons).

res.status(code)

Sets the HTTP-status for the response. Returns this for chaining purposes.

res.flush() [@since 2024.09.1]

Flushes the current response to the client immediately. Should typically only be used when streaming data (i.e. ai.streamText).

res.cookie(cookie)

Adds a cookie. The cookie parameter is an object that can have the following properties.

Note! Setting cookies does not work when the servlet response is committed, i.e. when rendering has started.

Cookie options

Property

Type

Description

Default

Since

name

String

The name of the cookie



value

String

The value of the cookie



httpOnly

Boolean

Flag to prevent client side scripts from accessing the cookie

false

5.0

secure

Boolean

Sets the cookie to be used with HTTPS only

false

5.0

maxAge

Number

The maximum age of the cookie in seconds.

  • A positive value indicates that the cookie will expire after that many seconds.
  • A negative value indicates a session cookie.
  • A zero value deletes the cookie.

-1

5.0

sameSite

String

Determines in what contexts this cookie will be available/sent. Valid values (case-insensitive) are:

  • "None"
  • "Lax"
  • "Strict"

Invalid values will be treated as "no value is set by the app" (i.e. no same site attribute will be added to the cookie)


7.1

res.clearCookie(name [, path])

Clears a cookie given a name. If path is missing, it defaults to '/'.

Did you find the content on this page useful?