コード例 #1
0
    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)
コード例 #2
0
ファイル: httpd.py プロジェクト: vignesh1997/dvc
    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)