remote http: use Content-MD5 header if there is not ETag available

Fix #1412
This commit is contained in:
Mr. Outis
2019-01-28 19:02:41 -06:00
parent 423c212d3f
commit 3009a25ae2
3 changed files with 32 additions and 4 deletions
+16 -2
View File
@@ -17,12 +17,26 @@ class ETagHandler(SimpleHTTPRequestHandler):
SimpleHTTPRequestHandler.end_headers(self)
class ContentMD5Handler(SimpleHTTPRequestHandler):
def end_headers(self):
file = self.translate_path(self.path)
if not os.path.isdir(file) and os.path.exists(file):
with open(file, 'r') as fd:
md5 = hashlib.md5(fd.read().encode('utf8')).hexdigest()
self.send_header('Content-MD5', md5)
SimpleHTTPRequestHandler.end_headers(self)
class StaticFileServer:
__server_lock = threading.Lock()
def __init__(self):
def __init__(self, handler='etag'):
handler_class = ETagHandler if handler == 'etag' else ContentMD5Handler
self.__server_lock.acquire()
self.httpd = HTTPServer(('localhost', 8000), ETagHandler)
self.httpd = HTTPServer(('localhost', 8000), handler_class)
def __enter__(self):
self.server_thread = threading.Thread(target=self.httpd.serve_forever)