prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <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.
  
  </issue>
  <code>
  [start of scrapy/http/headers.py]
  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 of scrapy/http/headers.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: 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__
  
verification_info: {"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"}]}