summaryrefslogtreecommitdiff
path: root/django/http/request.py
diff options
context:
space:
mode:
authorDavid Wobrock <david.wobrock@gmail.com>2022-10-09 22:33:35 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-11-14 10:21:51 +0100
commit67da22f08e05018ea968fcacbac9ac37ea925d85 (patch)
tree86c50e012c53b6f7910e1d221e98a7195441e335 /django/http/request.py
parentb181cae2e3697b2e53b5b67ac67e59f3b05a6f0d (diff)
downloaddjango-67da22f08e05018ea968fcacbac9ac37ea925d85.tar.gz
Fixed #34074 -- Added headers argument to RequestFactory and Client classes.
Diffstat (limited to 'django/http/request.py')
-rw-r--r--django/http/request.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/django/http/request.py b/django/http/request.py
index 815544368b..6b51d23e97 100644
--- a/django/http/request.py
+++ b/django/http/request.py
@@ -461,6 +461,31 @@ class HttpHeaders(CaseInsensitiveMapping):
return None
return header.replace("_", "-").title()
+ @classmethod
+ def to_wsgi_name(cls, header):
+ header = header.replace("-", "_").upper()
+ if header in cls.UNPREFIXED_HEADERS:
+ return header
+ return f"{cls.HTTP_PREFIX}{header}"
+
+ @classmethod
+ def to_asgi_name(cls, header):
+ return header.replace("-", "_").upper()
+
+ @classmethod
+ def to_wsgi_names(cls, headers):
+ return {
+ cls.to_wsgi_name(header_name): value
+ for header_name, value in headers.items()
+ }
+
+ @classmethod
+ def to_asgi_names(cls, headers):
+ return {
+ cls.to_asgi_name(header_name): value
+ for header_name, value in headers.items()
+ }
+
class QueryDict(MultiValueDict):
"""