Resource mappers also have the opportunity to take part in response handling so that they can adjust the response headers if necessary. You may need to adapt the handling of the current request to the request headers supplied. 

Note that this cannot be used to change how the resource is mapped - the mapping is performed once only, but the response headers can be customized  every time the file is requested.

As an example, the Zipped-Resources plugin uses this mechanism to set the Content-Encoding header:

{code:java}
import org.grails.plugin.resource.mapper.MapperPhase

class ZipResourceMapper {

    static phase = MapperPhase.ALTERNATEREPRESENTATION
    
    /**
     * Rename the file to a hash of it's contents, and set caching headers 
     */
    def map(resource, config) {
        // Do the zipping
        ...
        
        // Set up response headers
        resource.requestProcessors << { req, resp ->
            resp.setHeader('Content-Encoding', 'gzip')
        }    
    }
}
{code}

Here the mapper adds a Closure that takes the request and response objects to the resource's requestProcessors list. These will be called in the order they are defined on the resource.

