如何让Chrome显示字节或剩余时间用于内容编码的下载

发布于 2025-01-31 14:17:27 字数 1924 浏览 3 评论 0原文

我正在编写一个提供大文件的HTTP应用程序,我希望Web浏览器显示剩余时间和/或字节的估计。但是,由于文件非常可压缩,因此我也想使用GZPICTIGHON的内容编码,但也希望浏览器自动解压缩下载,以便用户没有额外的步骤来手动执行此操作。

但是,似乎Chrome(101.0.4951.64)不会显示出剩余的GZENTECTENT下载时间的时间。 ”

from http.server import HTTPServer, BaseHTTPRequestHandler
import time
import zlib

class SlowHandler(BaseHTTPRequestHandler):
    def do_GET(self):
        self.send_response(200)
        self.send_header('content-disposition', 'attachment; filename="my.file"')
        self.send_header('content-length', '1000000000')
        self.send_header('content-encoding', 'gzip') # If commented out, Chrome shows time remaining
        self.end_headers()

        obj = zlib.compressobj(wbits=31)
        compressed = obj.compress(b'Some data to compress. Some more' * 10000)
        self.wfile.write(compressed)
        self.wfile.write(obj.flush()[:-1])
        self.wfile.flush()
        time.sleep(10)

httpd = HTTPServer(("0.0.0.0", 8006), SlowHandler)
httpd.serve_forever()

如果我访问http:// localhost:8006

”

但是如果我不通过评论该行,然后,它确实显示了剩余时间的估计:

”

即使在safari进行测试时,即使使用内容编码的标头,它似乎总是显示出剩下的内容:

有没有办法让Chrome显示有关内容编码的下载的估计值?

编辑:如果这是一个错误,请在 https:/ /bugs.chromium.org/p/chromium/issues/detail?id=1329738

I'm writing an HTTP application that serves large files, and I would like web browser to show an estimate of time and/or bytes remaining. However, I would also like to use gzipped content-encoding, since the files are quite compressible, but would also like the browser to automatically decompress the download so the user doesn't have an extra step to do this manually.

However, it seems as though Chrome (101.0.4951.64) won't show an estimate of time remaining for gzipped content-encoded downloads. The below simple HTTP server

from http.server import HTTPServer, BaseHTTPRequestHandler
import time
import zlib

class SlowHandler(BaseHTTPRequestHandler):
    def do_GET(self):
        self.send_response(200)
        self.send_header('content-disposition', 'attachment; filename="my.file"')
        self.send_header('content-length', '1000000000')
        self.send_header('content-encoding', 'gzip') # If commented out, Chrome shows time remaining
        self.end_headers()

        obj = zlib.compressobj(wbits=31)
        compressed = obj.compress(b'Some data to compress. Some more' * 10000)
        self.wfile.write(compressed)
        self.wfile.write(obj.flush()[:-1])
        self.wfile.flush()
        time.sleep(10)

httpd = HTTPServer(("0.0.0.0", 8006), SlowHandler)
httpd.serve_forever()

results in this if I go to http://localhost:8006

Chrome download not showing an estimate of time remaining

But if I don't send the content-encoding header by commenting out that line, then it does show an estimate of time remaining:

Chrome download showing an estimate of time remaining

When testing in Safari, even with the content-encoding header, it seems to always show an estimate of what's remaining:

Safari download showing an estimate of remaining

Is there a way to get Chrome to show such estimates even for content-encoded downloads?

Edit: in case this is a bug, have reported it at https://bugs.chromium.org/p/chromium/issues/detail?id=1329738

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文