Generated: Wed 2013-03-13 10:33 CET
Source file: /media/Envs/Envs/filer-gallery/lib/python2.7/site-packages/filer/server/backends/nginx.py
Stats: 0 executed, 13 missed, 2 excluded, 14 ignored
#-*- coding: utf-8 -*-
from django.http import HttpResponse
from filer.server.backends.base import ServerBase
class NginxXAccelRedirectServer(ServerBase):
"""
This returns a response with only headers set, so that nginx actually does
the serving
"""
def __init__(self, location, nginx_location):
"""
nginx_location
"""
self.location = location
self.nginx_location = nginx_location
def get_nginx_location(self, path):
return path.replace(self.location, self.nginx_location)
def serve(self, request, file_obj, **kwargs):
# we should not use get_mimetype() here, because it tries to access the file in the filesystem.
#response = HttpResponse(mimetype=self.get_mimetype(file.path))
response = HttpResponse()
del response['Content-Type']
nginx_path = self.get_nginx_location(file_obj.path)
response['X-Accel-Redirect'] = nginx_path
self.default_headers(request=request, response=response, file_obj=file_obj, **kwargs)
return response