setCookie

Description

Adds a header to the response to request the update of the cookie with the given name on the client.

Use the deleteCookie directive to delete a cookie.

Example

final Route route = setCookie(HttpCookie.create("userName", "paul"), () ->
  complete("The user was logged in")
);

// tests:
final HttpHeader expected = SetCookie.create(HttpCookie.create("userName", "paul"));

testRoute(route).run(HttpRequest.GET("/"))
  .assertEntity("The user was logged in")
  .assertHeaderExists(expected);
The source code for this page can be found here.