def cache_headers_valid(policy_name, headers):
 policy_headers = CACHE_POLICY_DIRECTIVES[policy_name]
 for (header_name, expected_vals) in policy_headers.items():
  found_vals = set(headers.get(header_name, []))
  if (header_name == 'cache-control'):
   parsed_cache_control = set()
   for cache_header in found_vals:
    for split_header in cache_header.split(','):
     cache_directive = split_header.strip().lower()
     parsed_cache_control.add(cache_directive)
   if (parsed_cache_control != expected_vals):
    return False
  elif (found_vals != expected_vals):
   return False
 return True

def cache_headers_valid ( policy_name , headers ) : policy_headers = CACHE_POLICY_DIRECTIVES [ policy_name ] for ( header_name , expected_vals ) in policy_headers . items ( ) : found_vals = set ( headers . get ( header_name , [ ] ) ) if ( header_name == 'cache-control' ) : parsed_cache_control = set ( ) for cache_header in found_vals : for split_header in cache_header . split ( ',' ) : cache_directive = split_header . strip ( ) . lower ( ) parsed_cache_control . add ( cache_directive ) if ( parsed_cache_control != expected_vals ) : return False elif ( found_vals != expected_vals ) : return False return True
check if a responses headers make sense given a cache policy .