We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Response.headers loses data on multiple values
https://github.com/scrapy/scrapy/issues/1262 reported that by default `response.headers` would only expose the first value of a header e.g. when casted as a `dict`, acknowledging that `response.headers.getlist` could be used instead to get all values.

I have just found out that the latter is not true:

```python
>>> from scrapy.http import Response
>>> response = Response("https://example.com", headers=(("a", "b"), ("a", "c")))
>>> response.headers.getlist("a")
[b'c']
```

I could verify the issue happening as far back as Scrapy 1.6, so it does not look like a recent bug.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `scrapy/http/headers.py`
Content:
```
1 from w3lib.http import headers_dict_to_raw
2 from scrapy.utils.datatypes import CaselessDict
3 from scrapy.utils.python import to_unicode
4 
5 
6 class Headers(CaselessDict):
7     """Case insensitive http headers dictionary"""
8 
9     def __init__(self, seq=None, encoding='utf-8'):
10         self.encoding = encoding
11         super().__init__(seq)
12 
13     def normkey(self, key):
14         """Normalize key to bytes"""
15         return self._tobytes(key.title())
16 
17     def normvalue(self, value):
18         """Normalize values to bytes"""
19         if value is None:
20             value = []
21         elif isinstance(value, (str, bytes)):
22             value = [value]
23         elif not hasattr(value, '__iter__'):
24             value = [value]
25 
26         return [self._tobytes(x) for x in value]
27 
28     def _tobytes(self, x):
29         if isinstance(x, bytes):
30             return x
31         elif isinstance(x, str):
32             return x.encode(self.encoding)
33         elif isinstance(x, int):
34             return str(x).encode(self.encoding)
35         else:
36             raise TypeError(f'Unsupported value type: {type(x)}')
37 
38     def __getitem__(self, key):
39         try:
40             return super().__getitem__(key)[-1]
41         except IndexError:
42             return None
43 
44     def get(self, key, def_val=None):
45         try:
46             return super().get(key, def_val)[-1]
47         except IndexError:
48             return None
49 
50     def getlist(self, key, def_val=None):
51         try:
52             return super().__getitem__(key)
53         except KeyError:
54             if def_val is not None:
55                 return self.normvalue(def_val)
56             return []
57 
58     def setlist(self, key, list_):
59         self[key] = list_
60 
61     def setlistdefault(self, key, default_list=()):
62         return self.setdefault(key, default_list)
63 
64     def appendlist(self, key, value):
65         lst = self.getlist(key)
66         lst.extend(self.normvalue(value))
67         self[key] = lst
68 
69     def items(self):
70         return ((k, self.getlist(k)) for k in self.keys())
71 
72     def values(self):
73         return [self[k] for k in self.keys()]
74 
75     def to_string(self):
76         return headers_dict_to_raw(self)
77 
78     def to_unicode_dict(self):
79         """ Return headers as a CaselessDict with unicode keys
80         and unicode values. Multiple values are joined with ','.
81         """
82         return CaselessDict(
83             (to_unicode(key, encoding=self.encoding),
84              to_unicode(b','.join(value), encoding=self.encoding))
85             for key, value in self.items())
86 
87     def __copy__(self):
88         return self.__class__(self)
89     copy = __copy__
90
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/scrapy/http/headers.py b/scrapy/http/headers.py
--- a/scrapy/http/headers.py
+++ b/scrapy/http/headers.py
@@ -1,3 +1,5 @@
+from collections.abc import Mapping
+
 from w3lib.http import headers_dict_to_raw
 from scrapy.utils.datatypes import CaselessDict
 from scrapy.utils.python import to_unicode
@@ -10,6 +12,13 @@
         self.encoding = encoding
         super().__init__(seq)
 
+    def update(self, seq):
+        seq = seq.items() if isinstance(seq, Mapping) else seq
+        iseq = {}
+        for k, v in seq:
+            iseq.setdefault(self.normkey(k), []).extend(self.normvalue(v))
+        super().update(iseq)
+
     def normkey(self, key):
         """Normalize key to bytes"""
         return self._tobytes(key.title())
@@ -86,4 +95,5 @@
 
     def __copy__(self):
         return self.__class__(self)
+
     copy = __copy__

{"golden_diff": "diff --git a/scrapy/http/headers.py b/scrapy/http/headers.py\n--- a/scrapy/http/headers.py\n+++ b/scrapy/http/headers.py\n@@ -1,3 +1,5 @@\n+from collections.abc import Mapping\n+\n from w3lib.http import headers_dict_to_raw\n from scrapy.utils.datatypes import CaselessDict\n from scrapy.utils.python import to_unicode\n@@ -10,6 +12,13 @@\n         self.encoding = encoding\n         super().__init__(seq)\n \n+    def update(self, seq):\n+        seq = seq.items() if isinstance(seq, Mapping) else seq\n+        iseq = {}\n+        for k, v in seq:\n+            iseq.setdefault(self.normkey(k), []).extend(self.normvalue(v))\n+        super().update(iseq)\n+\n     def normkey(self, key):\n         \"\"\"Normalize key to bytes\"\"\"\n         return self._tobytes(key.title())\n@@ -86,4 +95,5 @@\n \n     def __copy__(self):\n         return self.__class__(self)\n+\n     copy = __copy__\n", "issue": "Response.headers loses data on multiple values\nhttps://github.com/scrapy/scrapy/issues/1262 reported that by default `response.headers` would only expose the first value of a header e.g. when casted as a `dict`, acknowledging that `response.headers.getlist` could be used instead to get all values.\r\n\r\nI have just found out that the latter is not true:\r\n\r\n```python\r\n>>> from scrapy.http import Response\r\n>>> response = Response(\"https://example.com\", headers=((\"a\", \"b\"), (\"a\", \"c\")))\r\n>>> response.headers.getlist(\"a\")\r\n[b'c']\r\n```\r\n\r\nI could verify the issue happening as far back as Scrapy 1.6, so it does not look like a recent bug.\n", "before_files": [{"content": "from w3lib.http import headers_dict_to_raw\nfrom scrapy.utils.datatypes import CaselessDict\nfrom scrapy.utils.python import to_unicode\n\n\nclass Headers(CaselessDict):\n    \"\"\"Case insensitive http headers dictionary\"\"\"\n\n    def __init__(self, seq=None, encoding='utf-8'):\n        self.encoding = encoding\n        super().__init__(seq)\n\n    def normkey(self, key):\n        \"\"\"Normalize key to bytes\"\"\"\n        return self._tobytes(key.title())\n\n    def normvalue(self, value):\n        \"\"\"Normalize values to bytes\"\"\"\n        if value is None:\n            value = []\n        elif isinstance(value, (str, bytes)):\n            value = [value]\n        elif not hasattr(value, '__iter__'):\n            value = [value]\n\n        return [self._tobytes(x) for x in value]\n\n    def _tobytes(self, x):\n        if isinstance(x, bytes):\n            return x\n        elif isinstance(x, str):\n            return x.encode(self.encoding)\n        elif isinstance(x, int):\n            return str(x).encode(self.encoding)\n        else:\n            raise TypeError(f'Unsupported value type: {type(x)}')\n\n    def __getitem__(self, key):\n        try:\n            return super().__getitem__(key)[-1]\n        except IndexError:\n            return None\n\n    def get(self, key, def_val=None):\n        try:\n            return super().get(key, def_val)[-1]\n        except IndexError:\n            return None\n\n    def getlist(self, key, def_val=None):\n        try:\n            return super().__getitem__(key)\n        except KeyError:\n            if def_val is not None:\n                return self.normvalue(def_val)\n            return []\n\n    def setlist(self, key, list_):\n        self[key] = list_\n\n    def setlistdefault(self, key, default_list=()):\n        return self.setdefault(key, default_list)\n\n    def appendlist(self, key, value):\n        lst = self.getlist(key)\n        lst.extend(self.normvalue(value))\n        self[key] = lst\n\n    def items(self):\n        return ((k, self.getlist(k)) for k in self.keys())\n\n    def values(self):\n        return [self[k] for k in self.keys()]\n\n    def to_string(self):\n        return headers_dict_to_raw(self)\n\n    def to_unicode_dict(self):\n        \"\"\" Return headers as a CaselessDict with unicode keys\n        and unicode values. Multiple values are joined with ','.\n        \"\"\"\n        return CaselessDict(\n            (to_unicode(key, encoding=self.encoding),\n             to_unicode(b','.join(value), encoding=self.encoding))\n            for key, value in self.items())\n\n    def __copy__(self):\n        return self.__class__(self)\n    copy = __copy__\n", "path": "scrapy/http/headers.py"}], "after_files": [{"content": "from collections.abc import Mapping\n\nfrom w3lib.http import headers_dict_to_raw\nfrom scrapy.utils.datatypes import CaselessDict\nfrom scrapy.utils.python import to_unicode\n\n\nclass Headers(CaselessDict):\n    \"\"\"Case insensitive http headers dictionary\"\"\"\n\n    def __init__(self, seq=None, encoding='utf-8'):\n        self.encoding = encoding\n        super().__init__(seq)\n\n    def update(self, seq):\n        seq = seq.items() if isinstance(seq, Mapping) else seq\n        iseq = {}\n        for k, v in seq:\n            iseq.setdefault(self.normkey(k), []).extend(self.normvalue(v))\n        super().update(iseq)\n\n    def normkey(self, key):\n        \"\"\"Normalize key to bytes\"\"\"\n        return self._tobytes(key.title())\n\n    def normvalue(self, value):\n        \"\"\"Normalize values to bytes\"\"\"\n        if value is None:\n            value = []\n        elif isinstance(value, (str, bytes)):\n            value = [value]\n        elif not hasattr(value, '__iter__'):\n            value = [value]\n\n        return [self._tobytes(x) for x in value]\n\n    def _tobytes(self, x):\n        if isinstance(x, bytes):\n            return x\n        elif isinstance(x, str):\n            return x.encode(self.encoding)\n        elif isinstance(x, int):\n            return str(x).encode(self.encoding)\n        else:\n            raise TypeError(f'Unsupported value type: {type(x)}')\n\n    def __getitem__(self, key):\n        try:\n            return super().__getitem__(key)[-1]\n        except IndexError:\n            return None\n\n    def get(self, key, def_val=None):\n        try:\n            return super().get(key, def_val)[-1]\n        except IndexError:\n            return None\n\n    def getlist(self, key, def_val=None):\n        try:\n            return super().__getitem__(key)\n        except KeyError:\n            if def_val is not None:\n                return self.normvalue(def_val)\n            return []\n\n    def setlist(self, key, list_):\n        self[key] = list_\n\n    def setlistdefault(self, key, default_list=()):\n        return self.setdefault(key, default_list)\n\n    def appendlist(self, key, value):\n        lst = self.getlist(key)\n        lst.extend(self.normvalue(value))\n        self[key] = lst\n\n    def items(self):\n        return ((k, self.getlist(k)) for k in self.keys())\n\n    def values(self):\n        return [self[k] for k in self.keys()]\n\n    def to_string(self):\n        return headers_dict_to_raw(self)\n\n    def to_unicode_dict(self):\n        \"\"\" Return headers as a CaselessDict with unicode keys\n        and unicode values. Multiple values are joined with ','.\n        \"\"\"\n        return CaselessDict(\n            (to_unicode(key, encoding=self.encoding),\n             to_unicode(b','.join(value), encoding=self.encoding))\n            for key, value in self.items())\n\n    def __copy__(self):\n        return self.__class__(self)\n\n    copy = __copy__\n", "path": "scrapy/http/headers.py"}]}