Transfer-Encoding: gzip vs. Content-Encoding: gzip

前端 未结 2 573
轮回少年
轮回少年 2020-12-04 06:20

What is the current state of affairs when it comes to whether to do

Transfer-Encoding: gzip

or a

Content-Encoding: gzip
         


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-04 06:47

    Quoting Roy T. Fielding, one of the authors of RFC 2616:

    changing content-encoding on the fly in an inconsistent manner (neither "never" nor "always) makes it impossible for later requests regarding that content (e.g., PUT or conditional GET) to be handled correctly. This is, of course, why performing on-the-fly content-encoding is a stupid idea, and why I added Transfer-Encoding to HTTP as the proper way to do on-the-fly encoding without changing the resource.

    Source: https://issues.apache.org/bugzilla/show_bug.cgi?id=39727#c31

    In other words: Don't do on-the-fly Content-Encoding, use Transfer-Encoding instead!

    Edit: That is, unless you want to serve gzipped content to clients that only understand Content-Encoding. Which, unfortunately, seems to be most of them. But be aware that you leave the realms of the spec and might run into issues such as the one mentioned by Fielding as well as others, e.g. when caching proxies are involved.

提交回复
热议问题