Debian Codegraph @

django_downloadview/apache/response.py

raw
1 """Apache's specific responses."""
2
3 import os.path
4
5 from django_downloadview.response import ProxiedDownloadResponse, content_disposition
6
7
8 class XSendfileResponse(ProxiedDownloadResponse):
9 "Delegates serving file to Apache via X-Sendfile header."
10
11 def __init__(
12 self, file_path, content_type, basename=None, attachment=True, headers=None
13 ):
14 """Return a HttpResponse with headers for Apache X-Sendfile."""
15 # content-type must be provided only as keyword argument to response
16 if headers and content_type:
17 headers.pop("Content-Type", None)
18 super().__init__(content_type=content_type, headers=headers)
19 if attachment:
20 self.basename = basename or os.path.basename(file_path)
21 self["Content-Disposition"] = content_disposition(self.basename)
22 self["X-Sendfile"] = file_path