diff options
author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-06-13 10:11:41 +0200 |
---|---|---|
committer | Andrew Godwin <andrew@aeracode.org> | 2019-06-15 10:29:02 -0700 |
commit | 415e899dc46c2f8d667ff11d3e54eff759eaded4 (patch) | |
tree | 0f2db2cb4c2bebcab6fb12b594b8a3394112b714 /django/http/request.py | |
parent | 87f5d07eededc86f8ce1797fdfca7d4903ee0edc (diff) | |
download | django-415e899dc46c2f8d667ff11d3e54eff759eaded4.tar.gz |
Refs #30451 -- Added HttpRequest._set_content_type_params() hook.
Diffstat (limited to 'django/http/request.py')
-rw-r--r-- | django/http/request.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/django/http/request.py b/django/http/request.py index e62e2272b2..804db6bf66 100644 --- a/django/http/request.py +++ b/django/http/request.py @@ -1,3 +1,5 @@ +import cgi +import codecs import copy import re from io import BytesIO @@ -69,6 +71,17 @@ class HttpRequest: def headers(self): return HttpHeaders(self.META) + def _set_content_type_params(self, meta): + """Set content_type, content_params, and encoding.""" + self.content_type, self.content_params = cgi.parse_header(meta.get('CONTENT_TYPE', '')) + if 'charset' in self.content_params: + try: + codecs.lookup(self.content_params['charset']) + except LookupError: + pass + else: + self.encoding = self.content_params['charset'] + def _get_raw_host(self): """ Return the HTTP host using the environment or request headers. Skip |