summaryrefslogtreecommitdiff
path: root/django/http
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
parentb181cae2e3697b2e53b5b67ac67e59f3b05a6f0d (diff)
Fixed #34074 -- Added headers argument to RequestFactory and Client classes.
Diffstat (limited to 'django/http')
-rw-r--r--django/http/__init__.py2
-rw-r--r--django/http/request.py25
2 files changed, 27 insertions, 0 deletions
diff --git a/django/http/__init__.py b/django/http/__init__.py
index 87109059a3..628564ea09 100644
--- a/django/http/__init__.py
+++ b/django/http/__init__.py
@@ -1,5 +1,6 @@
from django.http.cookie import SimpleCookie, parse_cookie
from django.http.request import (
+ HttpHeaders,
HttpRequest,
QueryDict,
RawPostDataException,
@@ -27,6 +28,7 @@ from django.http.response import (
__all__ = [
"SimpleCookie",
"parse_cookie",
+ "HttpHeaders",
"HttpRequest",
"QueryDict",
"RawPostDataException",
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):
"""