<commit_before>from .settings import MEDIA_URL
from django.utils.cache import patch_cache_control
from django.utils.http import http_date
import time

class MediaMiddleware(object):
    """
    Middleware for handling correct caching of media files. Removes
    ETags from media files to save unnecessary roundtrips.
    """

    MAX_AGE = 60*60*24*365

    def process_response(self, request, response):
        if not request.path.startswith(MEDIA_URL):
            return response

        for header in ('ETag', 'Expires', 'Cache-Control', 'Vary'):
            if response.has_header(header):
                del response[header]

        # Cache manifest files MUST NEVER be cached or you'll be unable to update
        # your cached app!!!
        if response['Content-Type'] != 'text/cache-manifest':
            patch_cache_control(response, public=True, max_age=self.MAX_AGE)
            response['Expires'] = http_date(time.time() + self.MAX_AGE)
        return response
<commit_msg>don't cache error responses<commit_after>from .settings import MEDIA_URL
from django.utils.cache import patch_cache_control
from django.utils.http import http_date
import time

class MediaMiddleware(object):
    """
    Middleware for handling correct caching of media files. Removes
    ETags from media files to save unnecessary roundtrips.
    """

    MAX_AGE = 60*60*24*365

    def process_response(self, request, response):
        if not request.path.startswith(MEDIA_URL):
            return response

        for header in ('ETag', 'Expires', 'Cache-Control', 'Vary'):
            if response.has_header(header):
                del response[header]

        # Cache manifest files MUST NEVER be cached or you'll be unable to update
        # your cached app!!!
        if response['Content-Type'] != 'text/cache-manifest' and \
                response.status_code == 200:
            patch_cache_control(response, public=True, max_age=self.MAX_AGE)
            response['Expires'] = http_date(time.time() + self.MAX_AGE)
        return response

{'fraction_non_alphanumeric': 0.09121951219512195, 'fraction_numerical': 0.01024390243902439, 'mean_word_length': 2.921606118546845, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1755049', 'n_tokens_mistral': 586, 'n_tokens_neox': 548, 'n_words': 170}