Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accept-Encoding: gzip on iOS

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?

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 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?

like image 651
Benjohn Avatar asked Aug 15 '14 20:08

Benjohn


People also ask

What does accept-Encoding gzip mean?

The Accept-Encoding header is used for negotiating content encoding. Accept-Encoding: gzip, deflate. The server responds with the scheme used, indicated by the Content-Encoding response header. Content-Encoding: gzip. Note that the server is not obligated to use any compression method.

How do you add accept-Encoding?

To check this Accept-Encoding in action go to Inspect Element -> Network check the request header for Accept-Encoding like below, Accept-Encoding is highlighted you can see.

Does Safari support gzip?

Safari does not decompress gzip content when Content-Encoding is gzip,gzip. Bookmark this question. Show activity on this post. Safari for OSX, iOS, and Windows is having issues decompressing Gzip content on my server after a recent server overhaul.

What does accept-Encoding mean?

The Accept-Encoding request HTTP header indicates the content encoding (usually a compression algorithm) that the client can understand. The server uses content negotiation to select one of the proposals and informs the client of that choice with the Content-Encoding response header.


1 Answers

It's all automatic, though I'm not immediately able to find an authoritative reference. You can prove it empirically using a proxy.

The best I can find so far: the iOS 7.1 Release Notes mention in passing that...

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.

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.

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.

like image 64
Tommy Avatar answered Oct 09 '22 09:10

Tommy