Content-Length maximum allowed length

14,311

There is no specific limit on the maximum value for the Content-Length.

https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.13

14.13 Content-Length
Any Content-Length greater than or equal to zero is a valid value.

Also the Apple documentation for setValue:forHTTPHeaderField: in the NSMutableURLRequest class reference states

Additionally, if the length of your upload body data can be determined automatically (for example, if you provide the body content with an NSData object), then the value of Content-Length is set for you.

Share:
14,311
Vincent
Author by

Vincent

If the code and the comments disagree, then both are probably wrong.

Updated on June 04, 2022

Comments

  • Vincent
    Vincent about 2 years

    I'm programming in ObjectiveC. I guess that all oC programmers are using the rather standard code for posting:

    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:NO];
    NSString *postLength = [NSString stringWithFormat:@"%d",[postData length]];
    
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    

    Currently I'm getting warning that NSUInteger should not be used as format argument. The warning suggest a type cast (unsigned long). And also replacing %d with %lu. That sounds logical.

    In the HTTP definition, I can not find how long the Content-Length may actually be. Just the rather vague Octet. Is that 8 bits? I can not find the answer!

  • Julian Reschke
    Julian Reschke over 9 years
    It says "a decimal number of octets"; what's unclear about that?
  • Clem
    Clem over 9 years
    A decimal number is not an Integer. So it cant be a number of Bytes
  • Julian Reschke
    Julian Reschke over 9 years
    A "decimal" number is a number expressed in the decimal system.
  • Clem
    Clem over 9 years
    upload.wikimedia.org/wikipedia/commons/0/07/NumberSetinR.svg It s said it s expressed wit number of digit too. A number of digit is a natural.
  • Julian Reschke
    Julian Reschke over 9 years
    A "number of octets" by definition is an integer. Also, die ABNF does not allow any character other than 0..9.
  • MSalters
    MSalters about 7 years
    "Decimal number" in this context means base-10. Compare this to HTTP chunk encoding, which uses a hexadecimal number (base 16).