It is nice to know that the NSURLConnection class supports gzip out of the box. The NSURLConnection class also does auto-decoding of the compressed data when the compressed content is received. However, by default even though the NSURLConnection class is handling this, it does not automatically add the required header to the HTTP request.
In order to inform the web server that the client is compression-aware and prefer to receive gzip-compressed content, you need to manually add the header to the HTTP request:
NSURL *url = [NSURL URLWithString:@"http://www.fubar.com/webservice.xml"];
NSMutableURLRequest* urlReq = [[NSMutableURLRequest alloc] initWithURL:url];
//add gzip-encoding to HTTP header
[urlReq setValue:@"gzip" forHTTPHeaderField:@"Accept-Encoding"];
If the web server supports gzip compression, the response that it returns to your Cocoa application or iPhone app will be compressed.
By utilizing gzip-compressed content, it reduces response time for a HTTP response because the size of the HTTP response is smaller. This may have a considerable impact to native iPhone apps that rely heavily on web services since the overall network traffic is optimized and data transfer is more responsive.
For those new to gzip compression, BetterExplained has a very good article explaining how gzip help in site optimization.