15

I am looking on the AFNetworking site that GZIP compression is supported " Gzip decompression from server responses is already built into AFNetworking, as NSURLConnection will automatically decompress responses with the Content-Encoding: gzip HTTP header. " - AFNetworking FAQ

How do I enable GZIP compression so I can pull data from the server compressed or is it already defaulting to this?

Thanks!

Alan
  • 9,331
  • 14
  • 52
  • 97

2 Answers2

19

AFAIK NSURLConnection uses gzip decompresson by default and AFNetworking builds on the top of NSURLConnection. So, you shouldn't have to enable it.

vbali
  • 795
  • 8
  • 15
  • 2
    Are we just going to take this guy's word for it? Please cite a source. – Snowman Sep 21 '15 at 13:33
  • @moby "this guy" took the pains to answer thank him and if you have doubt do your own research if it doesn't work down vote him till then take his word because this is SO not a court. – amar Oct 09 '15 at 06:25
  • How to get Response Data before compression? What layer does this decompression happen ?CFNetwork? – Beyond Chao Jan 05 '18 at 02:07
7

It seems you need to add a HTTP header :

[self setDefaultHeader:@"Accept-Encoding" value:@"gzip"]

To the AfNetworking HTTP client.

Thomas Decaux
  • 21,738
  • 2
  • 113
  • 124
  • so it's not enabled as default? – Alan Aug 23 '13 at 13:16
  • Run a Charles proxy and check ! I can say on my version of AFNetwork it was not. – Thomas Decaux Aug 23 '13 at 13:55
  • Thank you for the information. I am not familiar with networking. Before i had "[self setDefaultHeader:@"Accept" value:@"application/json"];" Can I have both? It seems if I replace it with the code above, it causes the app to crash. – Alan Aug 23 '13 at 16:58
  • I am not sure Accept is a valid HTTP header, you can check with HTTP protocol documentation, I think "Accept-Content" is what you need here. Of course you can have both, check with CharlesProxy if the HTTP headers have been really sent by your application. – Thomas Decaux Aug 24 '13 at 14:00
  • 6
    "Accept" is valid HTTP header. It describes what data format client expects (JSON,XML). "Accept-Encoding" HTTP header describes how the data will be transported (gzipped, plain text) over the web. – Opal Apr 03 '14 at 21:16