+
+ if ('X-ssi-restore' not in response and
+ getattr(request, 'ssi_patch_response', None)):
+ # We have some response modifiers set by ssi_includes and
+ # ssi_variables. Those are used, because unrendered SSI
+ # templates Django cache receives should have different
+ # caching headers, than pages rendered with request-specific
+ # information.
+ # What we do here is apply the modifiers, but restore
+ # previous values of any cache-relevant headers and set
+ # a custom header with modified values to set them
+ # after-cache.
+ original_fields = {}
+ for field in CACHE_HEADERS:
+ original_fields[field] = response.get(field, None)
+ for modifier in request.ssi_patch_response:
+ modifier(response)
+ restore_fields = {}
+ for field in CACHE_HEADERS:
+ new_value = response.get(field, None)
+ if new_value != original_fields[field]:
+ restore_fields[field] = new_value
+ if original_fields[field] is None:
+ del response[field]
+ else:
+ response[field] = original_fields[field]
+ response['X-ssi-restore'] = json_encode(restore_fields)
+