Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fixes #20459 -- Better example for set http header field, mention of header patch methods #1174

Closed
wants to merge 1 commit into from

1 participant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 19, 2013
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 2 deletions.
  1. +1 −0  AUTHORS
  2. +9 −2 docs/ref/request-response.txt
View
1  AUTHORS
@@ -627,6 +627,7 @@ answer newbie questions, and generally made Django that much better:
Gasper Zejn <zejn@kiberpipa.org>
Jarek Zgoda <jarek.zgoda@gmail.com>
Cheng Zhang
+ Jérémie Blaser <blaserje@gmail.com>
A big THANK YOU goes to:
View
11 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 present 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``
Something went wrong with that request. Please try again.