diff options
Diffstat (limited to 'django/http')
| -rw-r--r-- | django/http/__init__.py | 2 | ||||
| -rw-r--r-- | django/http/request.py | 25 |
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): """ |
