We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN 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.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pelican/server.py`
Content:
```
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 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()

```

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

{"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"}], "after_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\ntry:\n    from magic import from_file as magic_from_file\nexcept ImportError:\n    magic_from_file = None\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\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\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"}]}