From 3f372ef9d3a646a5c50599c001e472be074b5833 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Wed, 8 Nov 2017 10:02:30 -0500 Subject: [PATCH] [2.0.x] Fixed #28786 -- Doc'd middleware ordering considerations due to CommonMiddleware setting Content-Length. Backport of bc95314ca6af0b5e993ae07fdc7d8e6166d3b8ca from master --- docs/ref/middleware.txt | 4 +++- docs/releases/1.11.txt | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/ref/middleware.txt b/docs/ref/middleware.txt index 5c33d196d3..9a373d076d 100644 --- a/docs/ref/middleware.txt +++ b/docs/ref/middleware.txt @@ -488,7 +488,9 @@ Here are some hints about the ordering of various Django middleware classes: #. :class:`~django.middleware.common.CommonMiddleware` - Before any middleware that may change the response (it calculates ``ETags``). + Before any middleware that may change the response (it sets the ``ETag`` and + ``Content-Length`` headers). A middleware that appears before + ``CommonMiddleware`` and changes the response must reset the headers. After ``GZipMiddleware`` so it won't calculate an ``ETag`` header on gzipped contents. diff --git a/docs/releases/1.11.txt b/docs/releases/1.11.txt index ff4c1ebfef..9e84b869d3 100644 --- a/docs/releases/1.11.txt +++ b/docs/releases/1.11.txt @@ -730,6 +730,12 @@ Miscellaneous ``Content-Length`` header as this is now done by :class:`~django.middleware.common.CommonMiddleware`. + If you have a middleware that modifies a response's content and appears + before ``CommonMiddleware`` in the ``MIDDLEWARE`` or ``MIDDLEWARE_CLASSES`` + settings, you must reorder your middleware so that responses aren't modified + after ``Content-Length`` is set, or have the response modifying middleware + reset the ``Content-Length`` header. + * :meth:`~django.apps.AppConfig.get_model` and :meth:`~django.apps.AppConfig.get_models` now raise :exc:`~django.core.exceptions.AppRegistryNotReady` if they're called before