mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
remote http: use Content-MD5 header if there is not ETag available
Fix #1412
This commit is contained in:
+16
-2
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user