【问题标题】:NSURLCache and ETags with gzip enabled are not working启用 gzip 的 NSURLCache 和 ETag 不起作用
【发布时间】:2015-01-03 03:32:28
【问题描述】:

我试图让 NSURLCache 在 iOS8 上工作,但在使用 ETag 和 gzip 压缩时它似乎被破坏了。我正在使用启用了 gzip 压缩的 NGINX 作为瘦网络服务器的代理。以下响应没有被 NSURLCache 缓存:

HTTP/1.1 200 OK
Server            nginx/1.7.6
Date              Thu, 06 Nov 2014 14:28:50 GMT
Content-Type      application/json;charset=utf-8
Transfer-Encoding chunked
Connection        keep-alive
Vary              Accept-Encoding
Cache-Control     private, max-age=0
ETag              W/"d693ff4d26d0e7f25498ecb89d8796cd41e9da4f"
Content-Encoding  gzip

当我在 NGINX 配置中禁用 gzip 时,请求被正确缓存:

HTTP/1.1 200 OK
Server         nginx/1.7.6
Date           Thu, 06 Nov 2014 14:26:40 GMT
Content-Type   application/json;charset=utf-8
Content-Length 311433
Connection     keep-alive
Cache-Control  private, max-age=0
ETag           W/"d693ff4d26d0e7f25498ecb89d8796cd41e9da4f"

我尝试将 Cache-Control 设置为 public,但没有帮助。

我启用 gzip 的设置在 iOS7 上完美运行。

有人知道我做错了什么吗?还是我应该为此提交雷达?

提前致谢

【问题讨论】:

  • 我在 Apache 上,我对此也很生气。我尝试为“Accept-Encoding”请求标头设置“gzip,deflate”,我尝试使用 NSUrlSession,简单的 URLRequest + URLConnection 同步和异步。结果总是一样的。只有在请求文件的 .htaccess 上禁用 gzip/deflate 和 Vary 时,缓存才有效。
  • 嘿,你有没有找到使用 gzip 和 etag 的解决方法?

标签: ios caching ios8 gzip etag


【解决方案1】:

抱歉,无法评论,缺少声誉。

您可以尝试删除 ETag 中出现的所有 -gzip。这适用于我的自定义缓存机制。实际上,我正在寻找一种正确的方法来告诉NSURLSession 使用 gzip ETags。这感觉像是一种解决方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-26
    • 2014-01-16
    • 1970-01-01
    • 2016-06-07
    • 2013-07-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多