summaryrefslogtreecommitdiff
path: root/docs/ref
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2013-05-19 12:30:53 -0400
committerTim Graham <timograham@gmail.com>2013-05-19 12:30:53 -0400
commite83ff42792eb52235cacda58f3441673cc4e4c94 (patch)
tree1469fd1e21ce355d98d75f35644de0668c7ab352 /docs/ref
parent6786920fd8a1dfa43bba8333548c2496847298af (diff)
Fixed #20459 - Improved example for setting HTTP header fields.
Thanks Jérémie Blaser.
Diffstat (limited to 'docs/ref')
-rw-r--r--docs/ref/request-response.txt11
1 files changed, 9 insertions, 2 deletions
diff --git a/docs/ref/request-response.txt b/docs/ref/request-response.txt
index 10c3f32e60..9ff97e87d0 100644
--- a/docs/ref/request-response.txt
+++ b/docs/ref/request-response.txt
@@ -584,12 +584,19 @@ Setting header fields
To set or remove a header field in your response, treat it like a dictionary::
>>> response = HttpResponse()
- >>> response['Cache-Control'] = 'no-cache'
- >>> del response['Cache-Control']
+ >>> response['Age'] = 120
+ >>> del response['Age']
Note that unlike a dictionary, ``del`` doesn't raise ``KeyError`` if the header
field doesn't exist.
+For setting the ``Cache-Control`` and ``Vary`` header fields, it is recommended
+to use the :meth:`~django.utils.cache.patch_cache_control` and
+:meth:`~django.utils.cache.patch_vary_headers` methods from
+:mod:`django.utils.cache`, since these fields can have multiple, comma-separated
+values. The "patch" methods ensure that other values, e.g. added by a
+middleware, are not removed.
+
HTTP header fields cannot contain newlines. An attempt to set a header field
containing a newline character (CR or LF) will raise ``BadHeaderError``