def validate_image_redirect(response): if not response: response.failure("Response object is empty") if "/media/default/" in response.url: response.failure(f"Stub image URL in image redirect: {response.url}") class CacheValidator: def __init__(self): self._urls = set() def __call__(self, response): try: initial_response = response.history[0] except IndexError: initial_response = response cache_val = initial_response.headers.get("X-Cache") if initial_response.url not in self._urls: self._urls.add(initial_response.url) return if cache_val != "HIT": response.failure(f"No cache hit for URL: {initial_response.url}")