【问题标题】:How can I tell if Heroku is sending gzipped responses?如何判断 Heroku 是否发送压缩响应?
【发布时间】:2011-04-26 15:09:02
【问题描述】:

我正在制作一个从 Heroku 请求 JSON 的 iPhone 应用程序。

  1. 我收到的是压缩响应吗? 而且,iPhone 会自动 解压缩 gzip 后的回复,还是你 必须编程吗?我正在使用 NSURLConnection 异步 (使用委托协议)作为 在 Xcode 文档中描述。

    当我这样做时:

    curl -I http://acani.heroku.com/users/4c96ee4f1467281352000049/1234/50/50
    

    我明白了:

    HTTP/1.1 200 OK
    Server: nginx/0.7.67
    Date: Sun, 17 Oct 2010 16:27:25 GMT
    Content-Type: application/json
    Connection: keep-alive
    Content-Length: 11532
    X-Varnish: 2314841869
    Age: 0
    Via: 1.1 varnish
    
  2. 我还在使用 Zimt WebSocket 代码和 AsyncSocket 进行聊天。聊天服务器是 Node.js。我应该压缩每条聊天消息吗?还是自动完成的?

  3. 我想知道,为了减少带宽,Twitter 是否会先压缩您的推文(在 Web 上使用 JavaScript,或者在 iPhone 上使用 Objective-C),然后再发送到 Twitter?

谢谢!

马特

【问题讨论】:

    标签: http compression gzip nsurlconnection websocket


    【解决方案1】:

    要检测响应是否被压缩,您需要查找 Content-Encoding 标头。它可以设置为gzipcompressdeflate。有关详细信息,请参阅RFC 2616 第 3.5 节。

    【讨论】:

    • 谢谢。很高兴知道。现在,我如何告诉 heroku 为 Sinatra 使用 gzip?
    • HTTP 服务器不允许压缩响应,除非客户端的请求表明支持压缩。这是通过Accept-Encoding 请求标头完成的,该标头指定客户端识别的以逗号分隔的编码列表。然后,服务器可以选择其中一个并在 Content-Encoding 响应标头中指定。
    【解决方案2】:

    请不要将 RFС 用于任何与标准相关的常量。我想推荐使用iana registries。如果您需要Content-Encoding,则可以使用http-parameters.xml

    HTTP 内容编码注册表:

    aes128gcm
    br
    compress
    deflate
    exi
    gzip
    identity
    pack200-gzip
    x-compress
    x-gzip
    zstd
    

    你可以做更好的解决方案:

    #!/bin/sh
    
    torsocks wget \
      --recursive \
      --domains "iana.org" \
      --no-parent "https://www.iana.org/protocols" \
      --accept-regex "https://www.iana.org/(assignments|protocols)/.*"
    
    git init
    ./download.sh
    git add . && git commit
    

    您需要从标准中找到任何常量吗?只需 grep iana 文件夹。 您需要熟悉所有最近的变化吗? download.sh && git diff.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-11-07
      • 1970-01-01
      • 2023-03-25
      • 1970-01-01
      • 1970-01-01
      • 2011-11-09
      • 2013-12-02
      相关资源
      最近更新 更多