prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  response.body is duplicate
  Access the [text page(not mine)](http://files.qidian.com/Author4/3615059/88542882.txt) by browsers or wget and you will find  the response content is not duplicate, but scrapy's `response.body` is duplicate. I had tried set the scrapy's headers same as a real brower's, but it is still duplicate.
  
  Just use the follow sample code, and you will find the issue.
  
  ```
  scrapy shell "http://files.qidian.com/Author4/3615059/88542882.txt"
  ```
  
  Sorry for my bad english. 
  
  
  </issue>
  <code>
  [start of scrapy/utils/gz.py]
  1 import struct
  2 
  3 try:
  4     from cStringIO import StringIO as BytesIO
  5 except ImportError:
  6     from io import BytesIO
  7 from gzip import GzipFile
  8 
  9 import six
  10 import re
  11 
  12 # - Python>=3.5 GzipFile's read() has issues returning leftover
  13 #   uncompressed data when input is corrupted
  14 #   (regression or bug-fix compared to Python 3.4)
  15 # - read1(), which fetches data before raising EOFError on next call
  16 #   works here but is only available from Python>=3.3
  17 # - scrapy does not support Python 3.2
  18 # - Python 2.7 GzipFile works fine with standard read() + extrabuf
  19 if six.PY2:
  20     def read1(gzf, size=-1):
  21         return gzf.read(size)
  22 else:
  23     def read1(gzf, size=-1):
  24         return gzf.read1(size)
  25 
  26 
  27 def gunzip(data):
  28     """Gunzip the given data and return as much data as possible.
  29 
  30     This is resilient to CRC checksum errors.
  31     """
  32     f = GzipFile(fileobj=BytesIO(data))
  33     output = b''
  34     chunk = b'.'
  35     while chunk:
  36         try:
  37             chunk = read1(f, 8196)
  38             output += chunk
  39         except (IOError, EOFError, struct.error):
  40             # complete only if there is some data, otherwise re-raise
  41             # see issue 87 about catching struct.error
  42             # some pages are quite small so output is '' and f.extrabuf
  43             # contains the whole page content
  44             if output or getattr(f, 'extrabuf', None):
  45                 try:
  46                     output += f.extrabuf
  47                 finally:
  48                     break
  49             else:
  50                 raise
  51     return output
  52 
  53 _is_gzipped = re.compile(br'^application/(x-)?gzip\b', re.I).search
  54 _is_octetstream = re.compile(br'^(application|binary)/octet-stream\b', re.I).search
  55 
  56 def is_gzipped(response):
  57     """Return True if the response is gzipped, or False otherwise"""
  58     ctype = response.headers.get('Content-Type', b'')
  59     cenc = response.headers.get('Content-Encoding', b'').lower()
  60     return (_is_gzipped(ctype) or
  61             (_is_octetstream(ctype) and cenc in (b'gzip', b'x-gzip')))
  62
  [end of scrapy/utils/gz.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/utils/gz.py b/scrapy/utils/gz.py
  --- a/scrapy/utils/gz.py
  +++ b/scrapy/utils/gz.py
  @@ -43,7 +43,7 @@
               # contains the whole page content
               if output or getattr(f, 'extrabuf', None):
                   try:
  -                    output += f.extrabuf
  +                    output += f.extrabuf[-f.extrasize:]
                   finally:
                       break
               else:
  
verification_info: {"golden_diff": "diff --git a/scrapy/utils/gz.py b/scrapy/utils/gz.py\n--- a/scrapy/utils/gz.py\n+++ b/scrapy/utils/gz.py\n@@ -43,7 +43,7 @@\n             # contains the whole page content\n             if output or getattr(f, 'extrabuf', None):\n                 try:\n-                    output += f.extrabuf\n+                    output += f.extrabuf[-f.extrasize:]\n                 finally:\n                     break\n             else:\n", "issue": "response.body is duplicate\nAccess the [text page(not mine)](http://files.qidian.com/Author4/3615059/88542882.txt) by browsers or wget and you will find  the response content is not duplicate, but scrapy's `response.body` is duplicate. I had tried set the scrapy's headers same as a real brower's, but it is still duplicate.\n\nJust use the follow sample code, and you will find the issue.\n\n```\nscrapy shell \"http://files.qidian.com/Author4/3615059/88542882.txt\"\n```\n\nSorry for my bad english. \n\n", "before_files": [{"content": "import struct\n\ntry:\n    from cStringIO import StringIO as BytesIO\nexcept ImportError:\n    from io import BytesIO\nfrom gzip import GzipFile\n\nimport six\nimport re\n\n# - Python>=3.5 GzipFile's read() has issues returning leftover\n#   uncompressed data when input is corrupted\n#   (regression or bug-fix compared to Python 3.4)\n# - read1(), which fetches data before raising EOFError on next call\n#   works here but is only available from Python>=3.3\n# - scrapy does not support Python 3.2\n# - Python 2.7 GzipFile works fine with standard read() + extrabuf\nif six.PY2:\n    def read1(gzf, size=-1):\n        return gzf.read(size)\nelse:\n    def read1(gzf, size=-1):\n        return gzf.read1(size)\n\n\ndef gunzip(data):\n    \"\"\"Gunzip the given data and return as much data as possible.\n\n    This is resilient to CRC checksum errors.\n    \"\"\"\n    f = GzipFile(fileobj=BytesIO(data))\n    output = b''\n    chunk = b'.'\n    while chunk:\n        try:\n            chunk = read1(f, 8196)\n            output += chunk\n        except (IOError, EOFError, struct.error):\n            # complete only if there is some data, otherwise re-raise\n            # see issue 87 about catching struct.error\n            # some pages are quite small so output is '' and f.extrabuf\n            # contains the whole page content\n            if output or getattr(f, 'extrabuf', None):\n                try:\n                    output += f.extrabuf\n                finally:\n                    break\n            else:\n                raise\n    return output\n\n_is_gzipped = re.compile(br'^application/(x-)?gzip\\b', re.I).search\n_is_octetstream = re.compile(br'^(application|binary)/octet-stream\\b', re.I).search\n\ndef is_gzipped(response):\n    \"\"\"Return True if the response is gzipped, or False otherwise\"\"\"\n    ctype = response.headers.get('Content-Type', b'')\n    cenc = response.headers.get('Content-Encoding', b'').lower()\n    return (_is_gzipped(ctype) or\n            (_is_octetstream(ctype) and cenc in (b'gzip', b'x-gzip')))\n", "path": "scrapy/utils/gz.py"}]}