From 693e44e4125119414831fc149a914cf2d361eebb Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Wed, 2 Feb 2022 11:22:58 +0100 Subject: [PATCH] sources test: Support custom mimetypes in http server By creating a `foo.mimetype` file you can override the mimetype returned for the file `foo`. --- test/run/test_sources.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/run/test_sources.py b/test/run/test_sources.py index 66002e56..8cdbcc14 100644 --- a/test/run/test_sources.py +++ b/test/run/test_sources.py @@ -74,6 +74,14 @@ def runFileServer(barrier, directory): def __init__(self, request, client_address, server): super().__init__(request, client_address, server, directory=directory) + def guess_type(self, path): + try: + with open(path + ".mimetype", "r") as f: + return f.read().strip() + except FileNotFoundError: + pass + return super().guess_type(path) + httpd = socketserver.TCPServer(('', 80), Handler) barrier.wait() httpd.serve_forever()