From 67da22f08e05018ea968fcacbac9ac37ea925d85 Mon Sep 17 00:00:00 2001 From: David Wobrock Date: Sun, 9 Oct 2022 22:33:35 +0200 Subject: Fixed #34074 -- Added headers argument to RequestFactory and Client classes. --- django/http/request.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'django/http/request.py') 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): """ -- cgit v1.3