def end_headers(self): # RangeRequestHandler only sends Accept-Ranges header if Range header # is present, see https://github.com/danvk/RangeHTTPServer/issues/23 if not self.headers.get("Range"): self.send_header("Accept-Ranges", "bytes") # Add a checksum header file = self.translate_path(self.path) if not os.path.isdir(file) and os.path.exists(file): with open(file, "rb") as fd: data = fd.read() checksum = hashlib.md5(data).hexdigest() self.send_header("Content-MD5", checksum) RangeRequestHandler.end_headers(self)
def end_headers(self): # RangeRequestHandler only sends Accept-Ranges header if Range header # is present, see https://github.com/danvk/RangeHTTPServer/issues/23 if not self.headers.get("Range"): self.send_header("Accept-Ranges", "bytes") # Add a checksum header if self.checksum_header: file = self.translate_path(self.path) if not os.path.isdir(file) and os.path.exists(file): with open(file) as fd: encoded_text = fd.read().encode("utf8") checksum = hashlib.md5(encoded_text).hexdigest() self.send_header(self.checksum_header, checksum) RangeRequestHandler.end_headers(self)