1
0
mirror of https://github.com/django/django.git synced 2025-10-24 22:26:08 +00:00

Fixed #7581 -- Added streaming responses.

Thanks mrmachine and everyone else involved on this long-standing ticket.
This commit is contained in:
Aymeric Augustin
2012-10-20 17:40:14 +02:00
parent 300d052713
commit 4b27813198
18 changed files with 533 additions and 75 deletions

View File

@@ -19,7 +19,8 @@ from django.core.cache import get_cache
from django.core.cache.backends.base import (CacheKeyWarning,
InvalidCacheBackendError)
from django.db import router
from django.http import HttpResponse, HttpRequest, QueryDict
from django.http import (HttpResponse, HttpRequest, StreamingHttpResponse,
QueryDict)
from django.middleware.cache import (FetchFromCacheMiddleware,
UpdateCacheMiddleware, CacheMiddleware)
from django.template import Template
@@ -1416,6 +1417,29 @@ class CacheI18nTest(TestCase):
# reset the language
translation.deactivate()
@override_settings(
CACHE_MIDDLEWARE_KEY_PREFIX="test",
CACHE_MIDDLEWARE_SECONDS=60,
USE_ETAGS=True,
)
def test_middleware_with_streaming_response(self):
# cache with non empty request.GET
request = self._get_request_cache(query_string='foo=baz&other=true')
# first access, cache must return None
get_cache_data = FetchFromCacheMiddleware().process_request(request)
self.assertEqual(get_cache_data, None)
# pass streaming response through UpdateCacheMiddleware.
content = 'Check for cache with QUERY_STRING and streaming content'
response = StreamingHttpResponse(content)
UpdateCacheMiddleware().process_response(request, response)
# second access, cache must still return None, because we can't cache
# streaming response.
get_cache_data = FetchFromCacheMiddleware().process_request(request)
self.assertEqual(get_cache_data, None)
@override_settings(
CACHES={