Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 32b8dffe00
Fetching contributors…

Cannot retrieve contributors at this time

file 35 lines (27 sloc) 0.93 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
package grails.test.web

import spock.lang.Specification
import grails.test.mixin.TestFor
import spock.lang.Issue

@TestFor(YourController)
@Issue('GRAILS-9196')
class GetHeadersFromResponseSpec extends Specification{
    def "Test inspection of response headers"() {

        when:"An action that sets response headers is called"
            controller.index()

        then:"It is possible to inspect the mock response"
            response.header('Cache-Control') == 'no-cache' // that's fine
            "0" in response.headers('Expires') // will throw the exception

    }
}

class YourController {

    def index() {
        nocache(response)
        render ("foo")
    }

    void nocache(response) {
        response.setHeader('Cache-Control', 'no-cache') // HTTP 1.1
        response.addDateHeader('Expires', 0)
        response.setDateHeader('max-age', 0)
        response.addHeader('cache-Control', 'private')
    }
}
Something went wrong with that request. Please try again.