Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6328285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:25:56+00:00 2026-05-24T17:25:56+00:00

I wonder under what conditions an NSHTTPURLResponse object will not have key @Content-Length ?

  • 0

I wonder under what conditions an NSHTTPURLResponse object will not have key @”Content-Length” ? Is it usual/normal not to have that key?

I am trying something with the dropbox SDK and I’ve realized that

[[response allHeaderFields] objectForKey:@"Content-Length"]

returns nil and is causing downloadProgress to be infinite:

 NSInteger contentLength = [[[response allHeaderFields] objectForKey:@"Content-Length"] intValue];
    downloadProgress = (CGFloat)bytesDownloaded / (CGFloat)contentLength;

Is there any way I can make the response have that key?

BTW: This is the response I am getting

(gdb) po [response allHeaderFields]
{
    "Cache-Control" = "max-age=0";
    Connection = "keep-alive";
    "Content-Encoding" = gzip;
    "Content-Type" = "text/plain; charset=UTF-16LE";
    Date = "Wed, 10 Aug 2011 06:21:43 GMT";
    Etag = 228n;
    Pragma = public;
    Server = dbws;
    "Transfer-Encoding" = Identity;
}

EDIT (Work-arounded):

As @Mitchell said. Servers not always return such a key. (Weird DropBox servers, for png yes, for txt files sometimes no :/ )
So, in order to calculate the downloadProgress of a file I’ve modified (work-arounded) the source:

//In DBRequest.m 
- (void)connection:(NSURLConnection*)connection didReceiveData:(NSData*)data {
    ...
    bytesDownloaded += [data length];
    //start of modification
    //Server might not contain @"Content-Length" key, 
    //in that case use the downloadedBytes. Is better 
    //than having an infinite value because it could
    //be handled by DBRestClient's delegate. (If not 
    //it will have the same effect as infinite)
    if ([response expectedContentLength] == NSURLResponseUnknownLength ) {
        downloadProgress = (CGFloat)bytesDownloaded;
    }else{
        NSInteger contentLength = [[[response allHeaderFields] objectForKey:@"Content-Length"] intValue];
        downloadProgress = (CGFloat)bytesDownloaded / (CGFloat)contentLength; 
    }
    //end of modification
    if (downloadProgressSelector) {
        [target performSelector:downloadProgressSelector withObject:self];
    }
}

And since I have the size of a file from the metadata I can do:

- (void)restClient:(DBRestClient *)client loadProgress:(CGFloat)progress forFile:(NSString *)destPath {
    if (progress > 1) {//Work-around: This means the progress is not a 
        progress = progress/((CGFloat)(metadataOfTheFile.totalBytes));
    }
    ... update the progress bar here
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T17:25:56+00:00Added an answer on May 24, 2026 at 5:25 pm

    If you will recall that sometimes downloads in safari or your browser of choice don’t have a progress bar either, the length isn’t determined. In this particular case a loading spinner is the best thing to show. It entirely depends on the server returning the content-length, which is optional.

    I honestly don’t know why it isn’t returning that info, perhaps it’s due to the content-range or some other variable that it decides not to reveal it.

    You may have to look elsewhere to obtain that property, but the best recommendation is to be safe, rather than sorry and avoid all NaN errors.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Because I am not familiar with ADO under the hood, I was wonder which
I wonder how to specify to the command find for searching files under current
I wonder how to install a stable latest gcc (4.4.x) for a workstation under
wonder whether someone can help me with the following one... I have a struct
wonder if someone could help me with a little problem. I have session values
i wonder if the way i programm is right way or not. can you
I wonder what the REST API clients are available for using from Ruby (not
I'm thinking of developing a tool that runs under Visual Studio 2010 and am
I am building a Facebook application which should not be viewable to anyone under
I'm trying to implement this basic example found here : under the section titled

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.