Optimizations

Some reverse proxies allow applications to delegate actual download to the proxy:

  • with Django, manage permissions, generate files...
  • let the reverse proxy serve the file.

As a result, you get increased performance: reverse proxies are more efficient than Django at serving static files.

Currently, only nginx’s X-Accel [1] is supported, but contributions are welcome [2]!

How does it work?

The feature is inspired by Django’s TemplateResponse [3]: the download views return some django_downloadview.response.DownloadResponse instance. Such a response doesn’t contain file data.

By default, at the end of Django’s request/response handling, Django is to iterate over the content attribute of the response. In a DownloadResponse, this content attribute is a file wrapper.

It means that decorators and middlewares are given an opportunity to capture the DownloadResponse before the content of the file is loaded into memory As an example, django_downloadview.nginx.XAccelRedirectMiddleware replaces DownloadResponse intance by some django_downloadview.nginx.XAccelRedirectResponse.

Table Of Contents

Previous topic

Installation

Next topic

Nginx

This Page