2013-11-28 22:02:40 +00:00
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
from django.conf import settings
|
|
|
|
|
from django.core.files.storage import FileSystemStorage
|
|
|
|
|
|
|
|
|
|
from django_downloadview import StorageDownloadView
|
|
|
|
|
from django_downloadview.lighttpd import x_sendfile
|
|
|
|
|
|
2020-01-07 14:10:42 +00:00
|
|
|
storage_dir = os.path.join(settings.MEDIA_ROOT, "lighttpd")
|
2014-02-10 00:27:14 +00:00
|
|
|
storage = FileSystemStorage(
|
2020-01-07 14:10:42 +00:00
|
|
|
location=storage_dir, base_url="".join([settings.MEDIA_URL, "lighttpd/"])
|
|
|
|
|
)
|
2013-11-28 22:02:40 +00:00
|
|
|
|
|
|
|
|
|
2020-01-07 14:10:42 +00:00
|
|
|
optimized_by_middleware = StorageDownloadView.as_view(
|
|
|
|
|
storage=storage, path="hello-world.txt"
|
|
|
|
|
)
|
2013-11-28 22:02:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
optimized_by_decorator = x_sendfile(
|
2020-01-07 14:10:42 +00:00
|
|
|
StorageDownloadView.as_view(storage=storage, path="hello-world.txt"),
|
2013-11-28 22:02:40 +00:00
|
|
|
source_url=storage.base_url,
|
2020-01-07 14:10:42 +00:00
|
|
|
destination_dir="/lighttpd-optimized-by-decorator/",
|
|
|
|
|
)
|
2024-07-31 15:12:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def _modified_headers(request):
|
|
|
|
|
view = StorageDownloadView.as_view(storage=storage, path="hello-world.txt")
|
|
|
|
|
response = view(request)
|
2024-08-05 08:51:17 +00:00
|
|
|
response["X-Test"] = "header"
|
2024-07-31 15:12:03 +00:00
|
|
|
return response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
modified_headers = x_sendfile(
|
|
|
|
|
_modified_headers,
|
|
|
|
|
source_url=storage.base_url,
|
|
|
|
|
destination_dir="/lighttpd-modified-headers/",
|
|
|
|
|
)
|