V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
iqoo
V2EX  ›  程序员

所有浏览器请求头都会带 Accept-Encoding: gzip 吗

  •  
  •   iqoo · Aug 29, 2023 · 2461 views
    This topic created in 980 days ago, the information mentioned may be changed or developed.

    某个 HTTP 服务 只考虑基于浏览器的客户端,因此不论请求有没有带 Accept-Encoding: gzip ,响应一律带上 Content-Encoding: gzip 并返回 gzip 格式的数据。不知这样做是否过于激进有风险?

    目前来看几乎所有浏览器请求头都是包含 Accept-Encoding: gzip ,看起来问题也不大。但不知是否有某些非主流的小众浏览器,默认不支持压缩?

    4 replies    2023-08-30 16:59:21 +08:00
    ntdll
        1
    ntdll  
       Aug 29, 2023
    https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding#browser_compatibility

    >> Note that the server is not obligated to use any compression method. Compression highly depends on server settings and used server modules.

    原则上是关系不大的。
    wgit
        2
    wgit  
       Aug 29, 2023
    apache 和 nginx 都可以设置不使用 gzip 压缩
    具体返回什么样的由服务端做决定
    我在使用反向代理反代源站的时候就会关闭这个选项,不然有时候会内容替换失败
    tool2d
        3
    tool2d  
       Aug 29, 2023
    我还没见过不支持 gzip 的客户端,但是遇到 br 压缩就很头大了,chrome 是 https 才打开,遇到 http 必定关闭。

    明明压缩算法和 TLS 一点关系都没有,偏要绑定在一起。
    julyclyde
        4
    julyclyde  
       Aug 30, 2023
    理论上不应该强制发送压缩数据
    但是可以强制不压缩

    十几年前还有人反对给服务器上开启压缩,说“某些”浏览器不支持。我说那些浏览器的用户连支付宝都打不开,有什么价值啊
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2558 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 52ms · UTC 05:29 · PVG 13:29 · LAX 22:29 · JFK 01:29
    ♥ Do have faith in what you're doing.