From 4e1fd38bd6f007b6bb4cc57a0a841b78475a9d26 Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Fri, 7 Sep 2012 19:23:16 -0400 Subject: [PATCH] Fixed #18781 -- Reduced max session cookie size. --- django/contrib/messages/storage/cookie.py | 8 ++++---- django/contrib/messages/tests/base.py | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/django/contrib/messages/storage/cookie.py b/django/contrib/messages/storage/cookie.py index 5f64ccd0c5..6b5b016234 100644 --- a/django/contrib/messages/storage/cookie.py +++ b/django/contrib/messages/storage/cookie.py @@ -46,10 +46,10 @@ class CookieStorage(BaseStorage): Stores messages in a cookie. """ cookie_name = 'messages' - # We should be able to store 4K in a cookie, but Internet Explorer - # imposes 4K as the *total* limit for a domain. To allow other - # cookies, we go for 3/4 of 4K. - max_cookie_size = 3072 + # uwsgi's default configuration enforces a maximum size of 4kb for all the + # HTTP headers. In order to leave some room for other cookies and headers, + # restrict the session cookie to 1/2 of 4kb. See #18781. + max_cookie_size = 2048 not_finished = '__messagesnotfinished__' def _get(self, *args, **kwargs): diff --git a/django/contrib/messages/tests/base.py b/django/contrib/messages/tests/base.py index e9a67b0500..b3ced12773 100644 --- a/django/contrib/messages/tests/base.py +++ b/django/contrib/messages/tests/base.py @@ -152,7 +152,7 @@ class BaseTest(TestCase): cycle. """ data = { - 'messages': ['Test message %d' % x for x in range(10)], + 'messages': ['Test message %d' % x for x in range(5)], } show_url = reverse('django.contrib.messages.tests.urls.show') for level in ('debug', 'info', 'success', 'warning', 'error'): @@ -170,7 +170,7 @@ class BaseTest(TestCase): @override_settings(MESSAGE_LEVEL=constants.DEBUG) def test_with_template_response(self): data = { - 'messages': ['Test message %d' % x for x in range(10)], + 'messages': ['Test message %d' % x for x in range(5)], } show_url = reverse('django.contrib.messages.tests.urls.show_template_response') for level in self.levels.keys(): @@ -194,7 +194,7 @@ class BaseTest(TestCase): before a GET. """ data = { - 'messages': ['Test message %d' % x for x in range(10)], + 'messages': ['Test message %d' % x for x in range(5)], } show_url = reverse('django.contrib.messages.tests.urls.show') messages = [] @@ -226,7 +226,7 @@ class BaseTest(TestCase): when one attempts to store a message. """ data = { - 'messages': ['Test message %d' % x for x in range(10)], + 'messages': ['Test message %d' % x for x in range(5)], } show_url = reverse('django.contrib.messages.tests.urls.show') for level in ('debug', 'info', 'success', 'warning', 'error'): @@ -251,7 +251,7 @@ class BaseTest(TestCase): raised if 'fail_silently' = True """ data = { - 'messages': ['Test message %d' % x for x in range(10)], + 'messages': ['Test message %d' % x for x in range(5)], 'fail_silently': True, } show_url = reverse('django.contrib.messages.tests.urls.show')