prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  /files/ only serving attachments
  https://github.com/ipython/ipython/pull/6624 changes the behavior of serving html files from '/files/'.
  Instead of displaying a html page, I get the option to download it as file.
  
  Before I got as a response:
  
  ``` Python
  import requests
  r = requests.get('http://localhost:8888/files/Untitled10.html')
  print(r.headers)
  
  {'Last-Modified': 'Sat, 23 Aug 2014 16:03:02 GMT', 
  'Set-Cookie': 'username-localhost-8888=; expires=Thu, 31 Oct 2013 22:14:47 GMT; Path=/',
  'Content-Type': 'text/html', 'X-Frame-Options': 'SAMEORIGIN', 
  'Server': 'TornadoServer/4.0.2', 'Date': 'Fri, 31 Oct 2014 22:14:47 GMT', 
  'Content-Length': '237903', 'Accept-Ranges': 'bytes'}
  ```
  
  Now I get
  
  ``` Python
  r = requests.get('http://localhost:8888/files/Untitled10.html')
  print(r.headers)
  
  {'Date': 'Fri, 31 Oct 2014 22:17:27 GMT', 
  'Transfer-Encoding': 'chunked', 'X-Frame-Options': 'SAMEORIGIN', 
  'Set-Cookie': 'username-localhost-8888=; expires=Thu, 31 Oct 2013 22:17:27 GMT; Path=/',
   'Server': 'TornadoServer/4.0.2', 'Content-Type': 'text/html', 
  'Content-Disposition': 'attachment; filename="Untitled10.html"'}
  ```
  
  Is this an intended new behavior ?
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `IPython/html/files/handlers.py`
  Content:
  ```
  1 """Serve files directly from the ContentsManager."""
  2 
  3 # Copyright (c) IPython Development Team.
  4 # Distributed under the terms of the Modified BSD License.
  5 
  6 import os
  7 import mimetypes
  8 import json
  9 import base64
  10 
  11 from tornado import web
  12 
  13 from IPython.html.base.handlers import IPythonHandler
  14 
  15 class FilesHandler(IPythonHandler):
  16     """serve files via ContentsManager"""
  17 
  18     @web.authenticated
  19     def get(self, path):
  20         cm = self.settings['contents_manager']
  21         if cm.is_hidden(path):
  22             self.log.info("Refusing to serve hidden file, via 404 Error")
  23             raise web.HTTPError(404)
  24 
  25         path, name = os.path.split(path)
  26         model = cm.get_model(name, path)
  27 
  28         if model['type'] == 'notebook':
  29             self.set_header('Content-Type', 'application/json')
  30         else:
  31             cur_mime = mimetypes.guess_type(name)[0]
  32             if cur_mime is not None:
  33                 self.set_header('Content-Type', cur_mime)
  34         
  35         self.set_header('Content-Disposition','attachment; filename="%s"' % name)
  36 
  37         if model['format'] == 'base64':
  38             b64_bytes = model['content'].encode('ascii')
  39             self.write(base64.decodestring(b64_bytes))
  40         elif model['format'] == 'json':
  41             self.write(json.dumps(model['content']))
  42         else:
  43             self.write(model['content'])
  44         self.flush()
  45 
  46 default_handlers = [
  47     (r"/files/(.*)", FilesHandler),
  48 ]
  ```
  --- 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/IPython/html/files/handlers.py b/IPython/html/files/handlers.py
  --- a/IPython/html/files/handlers.py
  +++ b/IPython/html/files/handlers.py
  @@ -24,7 +24,10 @@
   
           path, name = os.path.split(path)
           model = cm.get_model(name, path)
  -
  +        
  +        if self.get_argument("download", False):
  +            self.set_header('Content-Disposition','attachment; filename="%s"' % name)
  +        
           if model['type'] == 'notebook':
               self.set_header('Content-Type', 'application/json')
           else:
  @@ -32,8 +35,6 @@
               if cur_mime is not None:
                   self.set_header('Content-Type', cur_mime)
           
  -        self.set_header('Content-Disposition','attachment; filename="%s"' % name)
  -
           if model['format'] == 'base64':
               b64_bytes = model['content'].encode('ascii')
               self.write(base64.decodestring(b64_bytes))
  
verification_info: {"golden_diff": "diff --git a/IPython/html/files/handlers.py b/IPython/html/files/handlers.py\n--- a/IPython/html/files/handlers.py\n+++ b/IPython/html/files/handlers.py\n@@ -24,7 +24,10 @@\n \n         path, name = os.path.split(path)\n         model = cm.get_model(name, path)\n-\n+        \n+        if self.get_argument(\"download\", False):\n+            self.set_header('Content-Disposition','attachment; filename=\"%s\"' % name)\n+        \n         if model['type'] == 'notebook':\n             self.set_header('Content-Type', 'application/json')\n         else:\n@@ -32,8 +35,6 @@\n             if cur_mime is not None:\n                 self.set_header('Content-Type', cur_mime)\n         \n-        self.set_header('Content-Disposition','attachment; filename=\"%s\"' % name)\n-\n         if model['format'] == 'base64':\n             b64_bytes = model['content'].encode('ascii')\n             self.write(base64.decodestring(b64_bytes))\n", "issue": "/files/ only serving attachments\nhttps://github.com/ipython/ipython/pull/6624 changes the behavior of serving html files from '/files/'.\nInstead of displaying a html page, I get the option to download it as file.\n\nBefore I got as a response:\n\n``` Python\nimport requests\nr = requests.get('http://localhost:8888/files/Untitled10.html')\nprint(r.headers)\n\n{'Last-Modified': 'Sat, 23 Aug 2014 16:03:02 GMT', \n'Set-Cookie': 'username-localhost-8888=; expires=Thu, 31 Oct 2013 22:14:47 GMT; Path=/',\n'Content-Type': 'text/html', 'X-Frame-Options': 'SAMEORIGIN', \n'Server': 'TornadoServer/4.0.2', 'Date': 'Fri, 31 Oct 2014 22:14:47 GMT', \n'Content-Length': '237903', 'Accept-Ranges': 'bytes'}\n```\n\nNow I get\n\n``` Python\nr = requests.get('http://localhost:8888/files/Untitled10.html')\nprint(r.headers)\n\n{'Date': 'Fri, 31 Oct 2014 22:17:27 GMT', \n'Transfer-Encoding': 'chunked', 'X-Frame-Options': 'SAMEORIGIN', \n'Set-Cookie': 'username-localhost-8888=; expires=Thu, 31 Oct 2013 22:17:27 GMT; Path=/',\n 'Server': 'TornadoServer/4.0.2', 'Content-Type': 'text/html', \n'Content-Disposition': 'attachment; filename=\"Untitled10.html\"'}\n```\n\nIs this an intended new behavior ?\n\n", "before_files": [{"content": "\"\"\"Serve files directly from the ContentsManager.\"\"\"\n\n# Copyright (c) IPython Development Team.\n# Distributed under the terms of the Modified BSD License.\n\nimport os\nimport mimetypes\nimport json\nimport base64\n\nfrom tornado import web\n\nfrom IPython.html.base.handlers import IPythonHandler\n\nclass FilesHandler(IPythonHandler):\n    \"\"\"serve files via ContentsManager\"\"\"\n\n    @web.authenticated\n    def get(self, path):\n        cm = self.settings['contents_manager']\n        if cm.is_hidden(path):\n            self.log.info(\"Refusing to serve hidden file, via 404 Error\")\n            raise web.HTTPError(404)\n\n        path, name = os.path.split(path)\n        model = cm.get_model(name, path)\n\n        if model['type'] == 'notebook':\n            self.set_header('Content-Type', 'application/json')\n        else:\n            cur_mime = mimetypes.guess_type(name)[0]\n            if cur_mime is not None:\n                self.set_header('Content-Type', cur_mime)\n        \n        self.set_header('Content-Disposition','attachment; filename=\"%s\"' % name)\n\n        if model['format'] == 'base64':\n            b64_bytes = model['content'].encode('ascii')\n            self.write(base64.decodestring(b64_bytes))\n        elif model['format'] == 'json':\n            self.write(json.dumps(model['content']))\n        else:\n            self.write(model['content'])\n        self.flush()\n\ndefault_handlers = [\n    (r\"/files/(.*)\", FilesHandler),\n]", "path": "IPython/html/files/handlers.py"}], "after_files": [{"content": "\"\"\"Serve files directly from the ContentsManager.\"\"\"\n\n# Copyright (c) IPython Development Team.\n# Distributed under the terms of the Modified BSD License.\n\nimport os\nimport mimetypes\nimport json\nimport base64\n\nfrom tornado import web\n\nfrom IPython.html.base.handlers import IPythonHandler\n\nclass FilesHandler(IPythonHandler):\n    \"\"\"serve files via ContentsManager\"\"\"\n\n    @web.authenticated\n    def get(self, path):\n        cm = self.settings['contents_manager']\n        if cm.is_hidden(path):\n            self.log.info(\"Refusing to serve hidden file, via 404 Error\")\n            raise web.HTTPError(404)\n\n        path, name = os.path.split(path)\n        model = cm.get_model(name, path)\n        \n        if self.get_argument(\"download\", False):\n            self.set_header('Content-Disposition','attachment; filename=\"%s\"' % name)\n        \n        if model['type'] == 'notebook':\n            self.set_header('Content-Type', 'application/json')\n        else:\n            cur_mime = mimetypes.guess_type(name)[0]\n            if cur_mime is not None:\n                self.set_header('Content-Type', cur_mime)\n        \n        if model['format'] == 'base64':\n            b64_bytes = model['content'].encode('ascii')\n            self.write(base64.decodestring(b64_bytes))\n        elif model['format'] == 'json':\n            self.write(json.dumps(model['content']))\n        else:\n            self.write(model['content'])\n        self.flush()\n\ndefault_handlers = [\n    (r\"/files/(.*)\", FilesHandler),\n]", "path": "IPython/html/files/handlers.py"}]}