Referencing HTTP headers in a hook script

Background

This article shows how to access HTTP headers from a hook script.

Example

The following groovy code can be used to access HTTP headers from a hook script.

def requestAttributes = org.springframework.web.context.request.RequestContextHolder.getRequestAttributes()
if (requestAttributes instanceof org.springframework.web.context.request.ServletRequestAttributes) {
    def request = ((org.springframework.web.context.request.ServletRequestAttributes) requestAttributes).getRequest()
	// Get the value of the 'set-cookie' response header
    def cookie = request.getHeader("set-cookie")
    if (cookie) {
		// Your logic
    }
}