3

I am trying to use setDownloadProgressBlock of AFHTTPRequestOperation class. The call back gives me 3 parameters:

( NSInteger bytesRead , NSInteger totalBytesRead , NSInteger totalBytesExpectedToRead ) 

In order for me to get the progress, I need the totalBytesExpectedToRead value, but it's giving me a -1. I checked the headers of the HTTP response and the content length is there...

{
    "Cache-Control" = "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
    Connection = "Keep-Alive";
    "Content-Encoding" = gzip;
    "Content-Length" = 36902;
    "Content-Type" = "text/plain";
    Date = "Sat, 03 Mar 2012 23:53:11 GMT";
    Expires = "Thu, 19 Nov 1981 08:52:00 GMT";
    "Keep-Alive" = "timeout=5, max=95";
    "Last-Modified" = "Sat, 03 Mar 2012 23:53:11 GMT";
    Pragma = "no-cache";
    Server = "Apache/2.2.20 (Ubuntu)";
    Vary = "Accept-Encoding";
    "X-Powered-By" = "PHP/5.3.6-13ubuntu3.3";
}

Is this a problem with the AFNetworking framework?

0xSina
  • 20,973
  • 34
  • 136
  • 253

1 Answers1

4

Please check the following response, it's a limitation of NSURLConnection related to the content being in gzip format: https://stackoverflow.com/a/7426735/250164

Community
  • 1
  • 1
Wolfgang Schreurs
  • 11,779
  • 7
  • 51
  • 92
  • Hi,Thanks for the input. Is there a way this gzip can be turned off? – 0xSina Mar 04 '12 at 00:04
  • I wouldn't advise it, but that's something you'd have to disable on the server. I would personally rather have my responses load faster than have a progress indicator to show me long it takes to load (that is, unless the data in question doesn't lend itself to gzip compression in the first place, like image data, which is already compressed). – mattt Mar 04 '12 at 03:10
  • 1
    You should be able to disable it on the client end by indicating via the request headers that you don't accept gzip data. – Steven Fisher Aug 10 '12 at 16:27
  • 1
    adding the header "Accept-Encoding:" with no arguments should solve the problem. – Renan May 15 '13 at 14:05
  • Doing a HEAD request before the GET would give you the information you need. – nil Sep 15 '13 at 20:09