Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #20459 - Improved example for setting HTTP header fields.

Thanks Jérémie Blaser.
  • Loading branch information...
commit e83ff42792eb52235cacda58f3441673cc4e4c94 1 parent 6786920
Tim Graham authored May 19, 2013
1  AUTHORS
@@ -111,6 +111,7 @@ answer newbie questions, and generally made Django that much better:
111 111
     Paul Bissex <http://e-scribe.com/>
112 112
     Loïc Bistuer <loic.bistuer@sixmedia.com>
113 113
     Simon Blanchard
  114
+    Jérémie Blaser <blaserje@gmail.com>
114 115
     Craig Blaszczyk <masterjakul@gmail.com>
115 116
     David Blewett <david@dawninglight.net>
116 117
     Artem Gnilov <boobsd@gmail.com>
11  docs/ref/request-response.txt
@@ -584,12 +584,19 @@ Setting header fields
584 584
 To set or remove a header field in your response, treat it like a dictionary::
585 585
 
586 586
     >>> response = HttpResponse()
587  
-    >>> response['Cache-Control'] = 'no-cache'
588  
-    >>> del response['Cache-Control']
  587
+    >>> response['Age'] = 120
  588
+    >>> del response['Age']
589 589
 
590 590
 Note that unlike a dictionary, ``del`` doesn't raise ``KeyError`` if the header
591 591
 field doesn't exist.
592 592
 
  593
+For setting the ``Cache-Control`` and ``Vary`` header fields, it is recommended
  594
+to use the :meth:`~django.utils.cache.patch_cache_control` and
  595
+:meth:`~django.utils.cache.patch_vary_headers` methods from
  596
+:mod:`django.utils.cache`, since these fields can have multiple, comma-separated
  597
+values. The "patch" methods ensure that other values, e.g. added by a
  598
+middleware, are not removed.
  599
+
593 600
 HTTP header fields cannot contain newlines. An attempt to set a header field
594 601
 containing a newline character (CR or LF) will raise ``BadHeaderError``
595 602
 

0 notes on commit e83ff42

Please sign in to comment.
Something went wrong with that request. Please try again.