prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN 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. 
  
  
  --- 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/utils/gz.py`
  Content:
  ```
  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 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()
  
  ```
  
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"}], "after_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[-f.extrasize:]\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"}]}