Package spark

Class Response

java.lang.Object
spark.Response

public class Response extends Object
Provides functionality for modifying the response
Author:
Per Wendel
  • Constructor Details

    • Response

      protected 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

      public void type(String contentType)
      Sets the content type for the response
      Parameters:
      contentType - the content type
    • type

      public String type()
      Returns the content type
      Returns:
      the content type
    • body

      public void body(String body)
      Sets the body
      Parameters:
      body - the body
    • body

      public 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(String location)
      Trigger a browser redirect
      Parameters:
      location - Where to redirect
    • redirect

      public void redirect(String location, int httpStatusCode)
      Trigger a browser redirect with specific http 3XX status code.
      Parameters:
      location - Where to redirect permanently
      httpStatusCode - the http status code
    • header

      public void header(String header, String value)
      Adds/Sets a response header
      Parameters:
      header - the header
      value - the value
    • header

      public void header(String header, int value)
      Adds/Sets a response header
      Parameters:
      header - the header
      value - the value
    • header

      public void header(String header, Date value)
      Adds/Sets a response header
      Parameters:
      header - the header
      value - the value
    • header

      public void header(String header, Date value)
      Adds/Sets a response header
      Parameters:
      header - the header
      value - the value
    • header

      public void header(String header, Instant value)
      Adds/Sets a response header
      Parameters:
      header - the header
      value - the value
    • cookie

      public void cookie(String name, 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 cookie
      value - value of the cookie
    • cookie

      public void cookie(String name, 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 cookie
      value - value of the cookie
      maxAge - max age of the cookie in seconds (negative for the not persistent cookie, zero - deletes the cookie)
    • cookie

      public void cookie(String name, 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 cookie
      value - value of the cookie
      maxAge - 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 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:
      name - name of the cookie
      value - value of the cookie
      maxAge - max age of the cookie in seconds (negative for the not persistent cookie, zero - deletes the cookie)
      secured - if true : cookie will be secured
      httpOnly - if true: cookie will be marked as http only
    • cookie

      public void cookie(String path, String name, 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 cookie
      name - name of the cookie
      value - value of the cookie
      maxAge - 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 cookie
      name - name of the cookie
      value - value of the cookie
      maxAge - max age of the cookie in seconds (negative for the not persistent cookie, zero - deletes the cookie)
      secured - if true : cookie will be secured
      httpOnly - 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 cookie
      path - path of the cookie
      name - name of the cookie
      value - value of the cookie
      maxAge - max age of the cookie in seconds (negative for the not persistent cookie, zero - deletes the cookie)
      secured - if true : cookie will be secured
      httpOnly - if true: cookie will be marked as http only
    • removeCookie

      public void removeCookie(String name)
      Removes the cookie.
      Parameters:
      name - name of the cookie
    • removeCookie

      public void removeCookie(String path, String name)
      Removes the cookie with given path and name.
      Parameters:
      path - path of the cookie
      name - name of the cookie