mirror of https://github.com/encode/starlette.git
Add Headers.mutablecopy()
This commit is contained in:
parent
31b25a8757
commit
140cf99df9
|
@ -155,6 +155,9 @@ class Headers(typing.Mapping[str, str]):
|
|||
if item_key == get_header_key
|
||||
]
|
||||
|
||||
def mutablecopy(self):
|
||||
return MutableHeaders(self._list[:])
|
||||
|
||||
def __getitem__(self, key: str):
|
||||
get_header_key = key.lower().encode("latin-1")
|
||||
for header_key, header_value in self._list:
|
||||
|
|
|
@ -51,6 +51,13 @@ def test_mutable_headers():
|
|||
assert dict(h) == {"b": "4"}
|
||||
|
||||
|
||||
def test_headers_mutablecopy():
|
||||
h = Headers([(b"a", b"123"), (b"a", b"456"), (b"b", b"789")])
|
||||
c = h.mutablecopy()
|
||||
assert c.items() == [("a", "123"), ("a", "456"), ("b", "789")]
|
||||
c["a"] = "abc"
|
||||
assert c.items() == [("b", "789"), ("a", "abc")]
|
||||
|
||||
def test_queryparams():
|
||||
q = QueryParams([("a", "123"), ("a", "456"), ("b", "789")])
|
||||
assert "a" in q
|
||||
|
|
Loading…
Reference in New Issue