Gives app scripts access to the current HTTP request and response, and to reading and writing cookies. An instance is bound as the 'http' script global for the duration of a request, so scripts read it as http.request, http.response, http.getCookie(...) and http.setCookie(...) rather than constructing it directly.

Group: Managers


Properties

PropertyReturnsDescription
requestRequestThe current HTTP request, for example to read a cookie from it: http.request.getCookie("return-url").
requestBodyStringReads the current request's body as text, buffering it on the request so repeated calls do not re-read the underlying input stream.
responseResponseThe current HTTP response, for example to set a cookie on it: http.response.setCookie("return-url", "/somewhere/i/belong").

Methods

getRequest()

Returns: Request

The current HTTP request, for example to read a cookie from it: http.request.getCookie("return-url").

getResponse()

Returns: Response

The current HTTP response, for example to set a cookie on it: http.response.setCookie("return-url", "/somewhere/i/belong").

getRequestBody()

Returns: String

Reads the current request's body as text, buffering it on the request so repeated calls do not re-read the underlying input stream.

setCookie(String name, Object value)

Returns: void

Sets a cookie on the current response with the root path and an expiry of one week. Equivalent to calling setCookie(name, value, 60 * 60 * 24 * 7, "/").

ParameterDescription
namethe name of the cookie; must be a valid cookie name
valuethe value to record on the cookie, converted to a string

setCookie(String name, String value, int expirySecs, String path)

Returns: void

Sets a cookie on the current response with a chosen expiry and path. The cookie's SameSite attribute is always set to Strict.

ParameterDescription
namethe name of the cookie; must be a valid cookie name
valuethe value to record on the cookie
expirySecsthe number of seconds the cookie will remain valid for
paththe URL path scope the cookie applies to

setCookie(String name, String value, int expirySecs, String path, String sameSite)

Returns: void

Sets a cookie on the current response with a chosen expiry, path and SameSite value. The sameSite argument is currently not applied to the cookie; the cookie is set with no explicit SameSite attribute.

ParameterDescription
namethe name of the cookie; must be a valid cookie name
valuethe value to record on the cookie
expirySecsthe number of seconds the cookie will remain valid for
paththe URL path scope the cookie applies to
sameSitethe intended SameSite value - None, Lax or Strict

cookieBuilder(String name)

Returns: CookieBuilder

Starts a fluent builder for a cookie, defaulting its SameSite attribute to Strict. Call build() on the returned builder to add the finished cookie to the current response.

ParameterDescription
namethe name of the cookie; must be a valid cookie name

getCookie(String name)

Returns: String

Reads the value of a cookie sent with the current request.

ParameterDescription
namethe name of the cookie to look up
To get full access to the Kademi Hub existing customers can login here, or new customers can register here.