Tagged: cookie

Working with cookies in Grails

I’m become a maintainer of Cookie Plugin for Grails.
And today happy to make it first production release.

To install it add compile ":cookie:1.0.1" dependency to BuildConfig.groovy.

Then you can use it via CookieService:

// This sets a cookie with the name `username` to the value `admin` with a expiration set to a week, defined in seconds
cookieService.setCookie('username', 'admin', 7 * 24 * 60)
// Or you can use named parameters:

    name: 'username', // Cookie name. Can't be blank or null and is case-sensitive
    value: 'admin', // Cookie value.
    maxAge: 30 * 60, // Age to store cookie in seconds; if negative, means the cookie is not stored; if zero, deletes the cookie.
    path: '/admin/', // A path to which the client should return the cookie. The cookie is visible to all the pages in the directory
    domain: '.example.com', // It begins with a dot (.example.com) and means that the cookie is visible to servers in a specified DNS zone
    secure: true, // Indicates to the browser whether the cookie should only be sent using a secure protocol, such as HTTPS or SSL.
    httpOnly: true // "HTTP Only" cookies are not supposed to be exposed to client-side JavaScript code, and may therefore help mitigate XSS attack.

// To get the cookie value
cookieService.getCookie('username') // returns 'admin'

cookieService.deleteCookie('username', '/admin/')

I will be thankful for any feedback and bug reports
Cookie Plugin on Grails.org