Package spark
Class Response
- java.lang.Object
-
- spark.Response
-
- Direct Known Subclasses:
ResponseWrapper
public class Response extends java.lang.Object
Provides functionality for modifying the response
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
body()
returns the bodyvoid
body(java.lang.String body)
Sets the bodyvoid
cookie(java.lang.String name, java.lang.String value)
Adds not persistent cookie to the response.void
cookie(java.lang.String name, java.lang.String value, int maxAge)
Adds cookie to the response.void
cookie(java.lang.String name, java.lang.String value, int maxAge, boolean secured)
Adds cookie to the response.void
cookie(java.lang.String name, java.lang.String value, int maxAge, boolean secured, boolean httpOnly)
Adds cookie to the response.void
cookie(java.lang.String path, java.lang.String name, java.lang.String value, int maxAge, boolean secured)
Adds cookie to the response.void
cookie(java.lang.String path, java.lang.String name, java.lang.String value, int maxAge, boolean secured, boolean httpOnly)
Adds cookie to the response.void
cookie(java.lang.String domain, java.lang.String path, java.lang.String name, java.lang.String value, int maxAge, boolean secured, boolean httpOnly)
Adds cookie to the response.void
header(java.lang.String header, int value)
Adds/Sets a response headervoid
header(java.lang.String header, java.lang.String value)
Adds/Sets a response headervoid
header(java.lang.String header, java.sql.Date value)
Adds/Sets a response headervoid
header(java.lang.String header, java.time.Instant value)
Adds/Sets a response headervoid
header(java.lang.String header, java.util.Date value)
Adds/Sets a response headerjavax.servlet.http.HttpServletResponse
raw()
void
redirect(java.lang.String location)
Trigger a browser redirectvoid
redirect(java.lang.String location, int httpStatusCode)
Trigger a browser redirect with specific http 3XX status code.void
removeCookie(java.lang.String name)
Removes the cookie.void
removeCookie(java.lang.String path, java.lang.String name)
Removes the cookie with given path and name.int
status()
Returns the status codevoid
status(int statusCode)
Sets the status code for thejava.lang.String
type()
Returns the content typevoid
type(java.lang.String contentType)
Sets the content type for the response
-
-
-
Method Detail
-
status
public void status(int statusCode)
Sets the status code for the- Parameters:
statusCode
- the status code
-
status
public int status()
Returns the status code- Returns:
- the status code
-
type
public void type(java.lang.String contentType)
Sets the content type for the response- Parameters:
contentType
- the content type
-
type
public java.lang.String type()
Returns the content type- Returns:
- the content type
-
body
public void body(java.lang.String body)
Sets the body- Parameters:
body
- the body
-
body
public java.lang.String body()
returns the body- Returns:
- the body
-
raw
public javax.servlet.http.HttpServletResponse raw()
- Returns:
- the raw response object handed in by Jetty
-
redirect
public void redirect(java.lang.String location)
Trigger a browser redirect- Parameters:
location
- Where to redirect
-
redirect
public void redirect(java.lang.String location, int httpStatusCode)
Trigger a browser redirect with specific http 3XX status code.- Parameters:
location
- Where to redirect permanentlyhttpStatusCode
- the http status code
-
header
public void header(java.lang.String header, java.lang.String value)
Adds/Sets a response header- Parameters:
header
- the headervalue
- the value
-
header
public void header(java.lang.String header, int value)
Adds/Sets a response header- Parameters:
header
- the headervalue
- the value
-
header
public void header(java.lang.String header, java.util.Date value)
Adds/Sets a response header- Parameters:
header
- the headervalue
- the value
-
header
public void header(java.lang.String header, java.sql.Date value)
Adds/Sets a response header- Parameters:
header
- the headervalue
- the value
-
header
public void header(java.lang.String header, java.time.Instant value)
Adds/Sets a response header- Parameters:
header
- the headervalue
- the value
-
cookie
public void cookie(java.lang.String name, java.lang.String value)
Adds not persistent cookie to the response. Can be invoked multiple times to insert more than one cookie.- Parameters:
name
- name of the cookievalue
- value of the cookie
-
cookie
public void cookie(java.lang.String name, java.lang.String value, int maxAge)
Adds cookie to the response. Can be invoked multiple times to insert more than one cookie.- Parameters:
name
- name of the cookievalue
- value of the cookiemaxAge
- max age of the cookie in seconds (negative for the not persistent cookie, zero - deletes the cookie)
-
cookie
public void cookie(java.lang.String name, java.lang.String value, int maxAge, boolean secured)
Adds cookie to the response. Can be invoked multiple times to insert more than one cookie.- Parameters:
name
- name of the cookievalue
- value of the cookiemaxAge
- max age of the cookie in seconds (negative for the not persistent cookie, zero - deletes the cookie)secured
- if true : cookie will be secured
-
cookie
public void cookie(java.lang.String name, java.lang.String value, int maxAge, boolean secured, boolean httpOnly)
Adds cookie to the response. Can be invoked multiple times to insert more than one cookie.- Parameters:
name
- name of the cookievalue
- value of the cookiemaxAge
- max age of the cookie in seconds (negative for the not persistent cookie, zero - deletes the cookie)secured
- if true : cookie will be securedhttpOnly
- if true: cookie will be marked as http only
-
cookie
public void cookie(java.lang.String path, java.lang.String name, java.lang.String value, int maxAge, boolean secured)
Adds cookie to the response. Can be invoked multiple times to insert more than one cookie.- Parameters:
path
- path of the cookiename
- name of the cookievalue
- value of the cookiemaxAge
- max age of the cookie in seconds (negative for the not persistent cookie, zero - deletes the cookie)secured
- if true : cookie will be secured
-
cookie
public void cookie(java.lang.String path, java.lang.String name, java.lang.String value, int maxAge, boolean secured, boolean httpOnly)
Adds cookie to the response. Can be invoked multiple times to insert more than one cookie.- Parameters:
path
- path of the cookiename
- name of the cookievalue
- value of the cookiemaxAge
- max age of the cookie in seconds (negative for the not persistent cookie, zero - deletes the cookie)secured
- if true : cookie will be securedhttpOnly
- if true: cookie will be marked as http only
-
cookie
public void cookie(java.lang.String domain, java.lang.String path, java.lang.String name, java.lang.String value, int maxAge, boolean secured, boolean httpOnly)
Adds cookie to the response. Can be invoked multiple times to insert more than one cookie.- Parameters:
domain
- domain of the cookiepath
- path of the cookiename
- name of the cookievalue
- value of the cookiemaxAge
- max age of the cookie in seconds (negative for the not persistent cookie, zero - deletes the cookie)secured
- if true : cookie will be securedhttpOnly
- if true: cookie will be marked as http only
-
removeCookie
public void removeCookie(java.lang.String name)
Removes the cookie.- Parameters:
name
- name of the cookie
-
removeCookie
public void removeCookie(java.lang.String path, java.lang.String name)
Removes the cookie with given path and name.- Parameters:
path
- path of the cookiename
- name of the cookie
-
-