prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Built-in server relies on file name suffix to guess Content-Type
  Pelican's built-in web server relies on the standard `SimpleHTTPServer` module to guess the appropriate `Content-Type` header for the files it serves. Sadly, that implementation relies on file name suffix to make its guesses. When I configure my site to use URLs without suffixes...
  
  ```
  'PAGE_URL': 'pages/{slug}'
  ```
  
  ...the server sends `Content-Type: application/octet-stream`, and my browser refuses to render the HTML.
  
  This could be better, at least on systems that have the python-magic package installed.
  
  
  </issue>
  <code>
  [start of pelican/server.py]
  1 from __future__ import print_function
  2 import os
  3 import sys
  4 import logging
  5 try:
  6     import SimpleHTTPServer as srvmod
  7 except ImportError:
  8     import http.server as srvmod  # NOQA
  9 
  10 try:
  11     import SocketServer as socketserver
  12 except ImportError:
  13     import socketserver  # NOQA
  14 
  15 PORT = len(sys.argv) in (2, 3) and int(sys.argv[1]) or 8000
  16 SERVER = len(sys.argv) == 3 and sys.argv[2] or ""
  17 SUFFIXES = ['', '.html', '/index.html']
  18 
  19 
  20 class ComplexHTTPRequestHandler(srvmod.SimpleHTTPRequestHandler):
  21     def do_GET(self):
  22         # Try to detect file by applying various suffixes
  23         for suffix in SUFFIXES:
  24             if not hasattr(self, 'original_path'):
  25                 self.original_path = self.path
  26 
  27             self.path = self.original_path + suffix
  28             path = self.translate_path(self.path)
  29 
  30             if os.path.exists(path):
  31                 srvmod.SimpleHTTPRequestHandler.do_GET(self)
  32                 logging.info("Found `%s`." % self.path)
  33                 break
  34 
  35             logging.info("Tried to find `%s`, but it doesn't exist.",
  36                          self.path)
  37         else:
  38             # Fallback if there were no matches
  39             logging.warning("Unable to find `%s` or variations.",
  40                             self.original_path)
  41 
  42 Handler = ComplexHTTPRequestHandler
  43 
  44 socketserver.TCPServer.allow_reuse_address = True
  45 try:
  46     httpd = socketserver.TCPServer((SERVER, PORT), Handler)
  47 except OSError as e:
  48     logging.error("Could not listen on port %s, server %s.", PORT, SERVER)
  49     sys.exit(getattr(e, 'exitcode', 1))
  50 
  51 
  52 logging.info("Serving at port %s, server %s.", PORT, SERVER)
  53 try:
  54     httpd.serve_forever()
  55 except KeyboardInterrupt as e:
  56     logging.info("Shutting down server.")
  57     httpd.socket.close()
  58
  [end of pelican/server.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/pelican/server.py b/pelican/server.py
  --- a/pelican/server.py
  +++ b/pelican/server.py
  @@ -12,6 +12,11 @@
   except ImportError:
       import socketserver  # NOQA
   
  +try:
  +    from magic import from_file as magic_from_file
  +except ImportError:
  +    magic_from_file = None
  +
   PORT = len(sys.argv) in (2, 3) and int(sys.argv[1]) or 8000
   SERVER = len(sys.argv) == 3 and sys.argv[2] or ""
   SUFFIXES = ['', '.html', '/index.html']
  @@ -39,6 +44,18 @@
               logging.warning("Unable to find `%s` or variations.",
                               self.original_path)
   
  +    def guess_type(self, path):
  +        """Guess at the mime type for the specified file.
  +        """
  +        mimetype = srvmod.SimpleHTTPRequestHandler.guess_type(self, path)
  +
  +        # If the default guess is too generic, try the python-magic library
  +        if mimetype == 'application/octet-stream' and magic_from_file:
  +            mimetype = magic_from_file(path, mime=True)
  +
  +        return mimetype
  +
  +
   Handler = ComplexHTTPRequestHandler
   
   socketserver.TCPServer.allow_reuse_address = True
  
verification_info: {"golden_diff": "diff --git a/pelican/server.py b/pelican/server.py\n--- a/pelican/server.py\n+++ b/pelican/server.py\n@@ -12,6 +12,11 @@\n except ImportError:\n     import socketserver  # NOQA\n \n+try:\n+    from magic import from_file as magic_from_file\n+except ImportError:\n+    magic_from_file = None\n+\n PORT = len(sys.argv) in (2, 3) and int(sys.argv[1]) or 8000\n SERVER = len(sys.argv) == 3 and sys.argv[2] or \"\"\n SUFFIXES = ['', '.html', '/index.html']\n@@ -39,6 +44,18 @@\n             logging.warning(\"Unable to find `%s` or variations.\",\n                             self.original_path)\n \n+    def guess_type(self, path):\n+        \"\"\"Guess at the mime type for the specified file.\n+        \"\"\"\n+        mimetype = srvmod.SimpleHTTPRequestHandler.guess_type(self, path)\n+\n+        # If the default guess is too generic, try the python-magic library\n+        if mimetype == 'application/octet-stream' and magic_from_file:\n+            mimetype = magic_from_file(path, mime=True)\n+\n+        return mimetype\n+\n+\n Handler = ComplexHTTPRequestHandler\n \n socketserver.TCPServer.allow_reuse_address = True\n", "issue": "Built-in server relies on file name suffix to guess Content-Type\nPelican's built-in web server relies on the standard `SimpleHTTPServer` module to guess the appropriate `Content-Type` header for the files it serves. Sadly, that implementation relies on file name suffix to make its guesses. When I configure my site to use URLs without suffixes...\n\n```\n'PAGE_URL': 'pages/{slug}'\n```\n\n...the server sends `Content-Type: application/octet-stream`, and my browser refuses to render the HTML.\n\nThis could be better, at least on systems that have the python-magic package installed.\n\n", "before_files": [{"content": "from __future__ import print_function\nimport os\nimport sys\nimport logging\ntry:\n    import SimpleHTTPServer as srvmod\nexcept ImportError:\n    import http.server as srvmod  # NOQA\n\ntry:\n    import SocketServer as socketserver\nexcept ImportError:\n    import socketserver  # NOQA\n\nPORT = len(sys.argv) in (2, 3) and int(sys.argv[1]) or 8000\nSERVER = len(sys.argv) == 3 and sys.argv[2] or \"\"\nSUFFIXES = ['', '.html', '/index.html']\n\n\nclass ComplexHTTPRequestHandler(srvmod.SimpleHTTPRequestHandler):\n    def do_GET(self):\n        # Try to detect file by applying various suffixes\n        for suffix in SUFFIXES:\n            if not hasattr(self, 'original_path'):\n                self.original_path = self.path\n\n            self.path = self.original_path + suffix\n            path = self.translate_path(self.path)\n\n            if os.path.exists(path):\n                srvmod.SimpleHTTPRequestHandler.do_GET(self)\n                logging.info(\"Found `%s`.\" % self.path)\n                break\n\n            logging.info(\"Tried to find `%s`, but it doesn't exist.\",\n                         self.path)\n        else:\n            # Fallback if there were no matches\n            logging.warning(\"Unable to find `%s` or variations.\",\n                            self.original_path)\n\nHandler = ComplexHTTPRequestHandler\n\nsocketserver.TCPServer.allow_reuse_address = True\ntry:\n    httpd = socketserver.TCPServer((SERVER, PORT), Handler)\nexcept OSError as e:\n    logging.error(\"Could not listen on port %s, server %s.\", PORT, SERVER)\n    sys.exit(getattr(e, 'exitcode', 1))\n\n\nlogging.info(\"Serving at port %s, server %s.\", PORT, SERVER)\ntry:\n    httpd.serve_forever()\nexcept KeyboardInterrupt as e:\n    logging.info(\"Shutting down server.\")\n    httpd.socket.close()\n", "path": "pelican/server.py"}]}