From 4fc35a9c3efdc9154efce28cb23cb84f8834517e Mon Sep 17 00:00:00 2001 From: Santiago Basulto Date: Fri, 4 May 2018 20:37:01 -0300 Subject: Fixed #20147 -- Added HttpRequest.headers. --- docs/ref/request-response.txt | 32 ++++++++++++++++++++++++++++++++ docs/releases/2.2.txt | 3 ++- 2 files changed, 34 insertions(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/ref/request-response.txt b/docs/ref/request-response.txt index 9e445ee4ff..84aa72da20 100644 --- a/docs/ref/request-response.txt +++ b/docs/ref/request-response.txt @@ -167,6 +167,38 @@ All attributes should be considered read-only, unless stated otherwise. underscores in WSGI environment variables. It matches the behavior of Web servers like Nginx and Apache 2.4+. + :attr:`HttpRequest.headers` is a simpler way to access all HTTP-prefixd + headers, plus ``CONTENT_LENGTH`` and ``CONTENT_TYPE``. + +.. attribute:: HttpRequest.headers + + .. versionadded:: 2.2 + + A case insensitive, dict-like object that provides access to all + HTTP-prefixed headers (plus ``Content-Length`` and ``Content-Type``) from + the request. + + The name of each header is stylized with title-casing (e.g. ``User-Agent``) + when it's displayed. You can access headers case-insensitively:: + + >>> request.headers + {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6', ...} + + >>> 'User-Agent' in request.headers + True + >>> 'user-agent' in request.headers + True + + >>> request.headers['User-Agent'] + Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) + >>> request.headers['user-agent'] + Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) + + >>> request.headers.get('User-Agent') + Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) + >>> request.headers.get('user-agent') + Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) + .. attribute:: HttpRequest.resolver_match An instance of :class:`~django.urls.ResolverMatch` representing the diff --git a/docs/releases/2.2.txt b/docs/releases/2.2.txt index 069e098664..fc2c296fce 100644 --- a/docs/releases/2.2.txt +++ b/docs/releases/2.2.txt @@ -266,7 +266,8 @@ Models Requests and Responses ~~~~~~~~~~~~~~~~~~~~~~ -* ... +* Added :attr:`.HttpRequest.headers` to allow simple access to a request's + headers. Serialization ~~~~~~~~~~~~~ -- cgit v1.3