Accept-Encoding: gzip on iOS
Asked Answered
T

1

18

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?

Transducer answered 15/8, 2014 at 20:36 Comment(0)
J
18

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.

Jene answered 15/8, 2014 at 21:18 Comment(4)
follow up of the answer above read URL Loading SystemSword
Hi @tommy, thanks – I've done a slight edit to the question to make clear that there are two parts to the question. I think you've given an answer to Q2, but not to Q1?Transducer
I've found a proper source for Q2 but the answer is 'yes' to both from experience. I'll keep hunting.Jene
Since you're the only one with concrete answer to these questions - I'll ask you one more: Will this also happen automatically also for upload requests? Suppose my body of a POST request is a huge ugly JSON - can I trust NSURLSession to deflate it before sending? Should I somehow tell it to do that? use specific extra headers? how to go about it?Reams

© 2022 - 2024 — McMap. All rights reserved.