5

Apparently, NSURLConnection automatically decodes gzipped responses. But, can it gzip encode its requests? If so, how? Or, does it do this automatically too?

Community
  • 1
  • 1
ma11hew28
  • 106,283
  • 107
  • 420
  • 616

2 Answers2

5

An HTTP request body cannot be gzipped at the protocol level, as there is no way for the client to know whether the server supports that or not; it works for the server response because the client indicates in the request whether a gzipped response body can be accepted. (It could be done in the future something like how Expect: 100-continue works, but that's not the situation we're faced with today).

At the application level, you certainly could gzip the request body. But that would be outside the realm of NSURLConnection.

Anomie
  • 86,459
  • 13
  • 122
  • 143
  • Interesting. Can you show an example of how to gzip a request to be sent with `NSURLConnection`? Or, would I have to use another library, like [ASIHTTP, that supports gzip compression of request bodies for POST & PUT](http://allseeing-i.com/ASIHTTPRequest/How-to-use#using_gzip_to_compress_request_bodies)? – ma11hew28 Jun 01 '11 at 16:10
0

I'm usually all for using NSURLRequests over ASIHTTPRequests, but ASI does handle this case. HTTP request compression isn't something you can use all the time safely. You can't detect whether a server will handle this correctly on a route. Even if you get Apache setup to handle this correctly it will fail when making requests on different modules since they might not handle it correctly.

http://allseeing-i.com/ASIHTTPRequest/How-to-use#using_gzip_to_compress_request_bodies

Gabe
  • 2,201
  • 1
  • 22
  • 17