1
0
mirror of https://github.com/httpie/cli.git synced 2025-08-10 22:42:05 +02:00

Support multiple headers sharing the same name (#1190)

* Support multiple headers sharing the same name

* Apply suggestions

* Don't normalize HTTP header names

* apply visual suggestions

Co-authored-by: Jakub Roztocil <jakub@roztocil.co>

* bump down multidict to 4.7.0

Co-authored-by: Jakub Roztocil <jakub@roztocil.co>
This commit is contained in:
Batuhan Taskaya
2021-10-31 15:04:39 +01:00
committed by GitHub
parent d40f06687f
commit 7cdd74fece
11 changed files with 221 additions and 13 deletions

View File

@@ -1,15 +1,41 @@
from collections import OrderedDict
from requests.structures import CaseInsensitiveDict
from multidict import MultiDict, CIMultiDict
class RequestHeadersDict(CaseInsensitiveDict):
class BaseMultiDict(MultiDict):
"""
Headers are case-insensitive and multiple values are currently not supported.
Base class for all MultiDicts.
"""
class RequestHeadersDict(CIMultiDict, BaseMultiDict):
"""
Headers are case-insensitive and multiple values are supported
through the `add()` API.
"""
def add(self, key, value):
"""
Add or update a new header.
If the given `value` is `None`, then all the previous
values will be overwritten and the value will be set
to `None`.
"""
if value is None:
self[key] = value
return None
# If the previous value for the given header is `None`
# then discard it since we are explicitly giving a new
# value for it.
if key in self and self.getone(key) is None:
self.popone(key)
super().add(key, value)
class RequestJSONDataDict(OrderedDict):
pass