Package spark
Class Response
java.lang.Object
spark.Response
- Direct Known Subclasses:
ResponseWrapper
Provides functionality for modifying the response
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbody()
returns the bodyvoid
Sets the bodyvoid
Adds not persistent cookie to the response.void
Adds cookie to the response.void
Adds cookie to the response.void
Adds cookie to the response.void
Adds cookie to the response.void
Adds cookie to the response.void
cookie
(String domain, String path, String name, String value, int maxAge, boolean secured, boolean httpOnly) Adds cookie to the response.void
Adds/Sets a response headervoid
Adds/Sets a response headervoid
Adds/Sets a response headervoid
Adds/Sets a response headervoid
Adds/Sets a response headerjavax.servlet.http.HttpServletResponse
raw()
void
Trigger a browser redirectvoid
Trigger a browser redirect with specific http 3XX status code.void
removeCookie
(String name) Removes the cookie.void
removeCookie
(String path, String name) Removes the cookie with given path and name.int
status()
Returns the status codevoid
status
(int statusCode) Sets the status code for thetype()
Returns the content typevoid
Sets the content type for the response
-
Field Details
-
LOG
private static final org.slf4j.Logger LOGThe logger. -
response
private javax.servlet.http.HttpServletResponse response -
body
-
-
Constructor Details
-
Response
protected Response() -
Response
Response(javax.servlet.http.HttpServletResponse response)
-
-
Method Details
-
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
Sets the content type for the response- Parameters:
contentType
- the content type
-
type
Returns the content type- Returns:
- the content type
-
body
Sets the body- Parameters:
body
- the body
-
body
returns the body- Returns:
- the body
-
raw
public javax.servlet.http.HttpServletResponse raw()- Returns:
- the raw response object handed in by Jetty
-
redirect
Trigger a browser redirect- Parameters:
location
- Where to redirect
-
redirect
Trigger a browser redirect with specific http 3XX status code.- Parameters:
location
- Where to redirect permanentlyhttpStatusCode
- the http status code
-
header
Adds/Sets a response header- Parameters:
header
- the headervalue
- the value
-
header
Adds/Sets a response header- Parameters:
header
- the headervalue
- the value
-
header
Adds/Sets a response header- Parameters:
header
- the headervalue
- the value
-
header
Adds/Sets a response header- Parameters:
header
- the headervalue
- the value
-
header
Adds/Sets a response header- Parameters:
header
- the headervalue
- the value
-
cookie
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
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
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
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
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(String path, String name, 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(String domain, String path, String name, 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
Removes the cookie.- Parameters:
name
- name of the cookie
-
removeCookie
Removes the cookie with given path and name.- Parameters:
path
- path of the cookiename
- name of the cookie
-