Ejemplo n.º 1
0
    def get(self, request, **kwargs):
        storage = CachedDatabaseStorage()
        filename = kwargs['filename']
        file = storage.open(filename, 'rb')
        file_content = file.read()
        content_type, encoding = mimetypes.guess_type(filename)
        response = HttpResponse(file_content, content_type=content_type)
        if encoding: # its already encoded (e.g. with gzip)
            response['Content-Encoding'] = encoding
            response['Content-Length'] = str(len(file_content))
        else: # gzip it
            gzip_middleware.process_response(request, response)

        # if we start using this for more than just images, the caching may be a bit extreme ... will need to rethink.
        expires = datetime.datetime.utcnow() + timedelta(days=(2 * 365)) # 2 yrs.
        response['Expires'] =  expires.strftime("%a, %d %b %Y %H:%M:%S GMT")
        response['Cache-Control'] = 'max-age=63072000, public' # 2 yrs
        return response
Ejemplo n.º 2
0
 def _last_modified(request, *args, **kwargs):
     storage = CachedDatabaseStorage()
     return storage.modified_time(kwargs['filename'])