Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions playwright/_impl/_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import json as json_utils
import mimetypes
import re
from collections import defaultdict
from pathlib import Path
from types import SimpleNamespace
from typing import (
Expand Down Expand Up @@ -1031,9 +1030,10 @@ def _on_close(self) -> None:
class RawHeaders:
def __init__(self, headers: HeadersArray) -> None:
self._headers_array = headers
self._headers_map: Dict[str, Dict[str, bool]] = defaultdict(dict)
self._headers_map: Dict[str, Dict[str, bool]] = {}
for header in headers:
self._headers_map[header["name"].lower()][header["value"]] = True
values = self._headers_map.setdefault(header["name"].lower(), {})
values[header["value"]] = True

@staticmethod
def _from_headers_dict_lossy(headers: Dict[str, str]) -> "RawHeaders":
Expand All @@ -1047,7 +1047,7 @@ def get(self, name: str) -> Optional[str]:
return separator.join(values)

def get_all(self, name: str) -> List[str]:
return list(self._headers_map[name.lower()].keys())
return list(self._headers_map.get(name.lower(), {}).keys())

def headers(self) -> Dict[str, str]:
result = {}
Expand Down
3 changes: 3 additions & 0 deletions tests/async/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,9 @@ async def test_response_headers_should_work(page: Page, server: Server) -> None:
assert response
assert response.headers["foo"] == "bar"
assert (await response.all_headers())["foo"] == "bar"
# Looking up a missing header must not add it.
assert await response.header_value("x-missing") is None
assert "x-missing" not in await response.all_headers()


async def test_request_post_data_should_work(page: Page, server: Server) -> None:
Expand Down
Loading