Accept-Encoding:iOS上的gzip [英] Accept-Encoding: gzip on iOS
问题描述
Q1 使用iOS App套件,我可以期待 接受编码:gzip
会自动使用,还是我需要在URL请求中的某处明确要求使用它?
Q1 With the iOS App kit, can I expect that Accept-Encoding: gzip
will be used automatically, or do I need to explicitly ask for it to be used by setting this in the URL request somewhere?
我正在使用调用 [NSData dataWithContentsOfURL:url]
,虽然我可能会改为专门设置NSURLSession - 这可能是自动的请求gzip编码?
I'm currently using the call [NSData dataWithContentsOfURL: url]
, although I am likely to change over to specifically setting up an NSURLSession – is this likely to automatically request gzip encoding?
Q2 此外,如果 并且服务器必须使用gzip-ed内容,我是否正确,客户端将自动解码压缩内容,以便我不需要?
Q2 Also, if it is used and the server obliges with gzip-ed content, am I correct that the client side will automatically decode the compressed content transparently so that I don't need to?
推荐答案
这一切都是自动,虽然我不能立即找到权威的参考。您可以使用代理凭经验证明。
It's all automatic, though I'm not immediately able to find an authoritative reference. You can prove it empirically using a proxy.
到目前为止我能找到的最好的: iOS 7.1发行说明顺便提一下......
The best I can find so far: the iOS 7.1 Release Notes mention in passing that...
已添加兼容性行为以解决某些
Web服务器将为
发送错误的Content-Length值的问题Content-Encoding: gzip内容。以前,NSURLConnection和
NSURLSession会在这种情况下发送网络连接丢失/
NSURLErrorNetworkConnectionLost(-1005)错误。
A compatibility behavior has been added to address an issue where some web servers would send the wrong Content-Length value for "Content-Encoding: gzip" content. Previously, NSURLConnection and NSURLSession would send a "network connection was lost" / NSURLErrorNetworkConnectionLost (-1005) error in this situation.
兼容性仅当Content-Length值
与扩展的gzip内容完全匹配时,行为才适用。它不适用于off
by 1或类似的错误计数。
The compatibility behavior applies only if the Content-Length value exactly matches the expanded gzip’d content. It won’t apply for "off by 1" or similar miscounting.
即。 NSURLConnection
和 NSURLSession
包含处理gzip内容的代码,并且在7.1之前肯定是这样做的(根据先前)。有趣的是,他们似乎从远古时代开始就这样做了,但无论如何,7.0+现在大约是应用下载市场的98%。
i.e. NSURLConnection
and NSURLSession
include code to handle gzip content, and definitely did so prior to 7.1 (as per the reference to "previously"). Anecdotally, they appear to have done so since time immemorial but in any case 7.0+ is about 98% of the app-downloading market now.
这篇关于Accept-Encoding:iOS上的gzip的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!