Add header accessors (#2696)

This commit is contained in:
Adam Hopkins
2023-02-28 00:26:53 +02:00
committed by GitHub
parent dfc0704831
commit cb49c2b26d
2 changed files with 54 additions and 1 deletions

View File

@@ -88,6 +88,12 @@ class Header(CIMultiDict):
very similar to a regular dictionary.
"""
def __getattr__(self, key: str) -> str:
if key.startswith("_"):
return self.__getattribute__(key)
key = key.rstrip("_").replace("_", "-")
return ",".join(self.getall(key, default=[]))
def get_all(self, key: str):
"""
Convenience method mapped to ``getall()``.