"content-length" unavailable when Transfer-Encoding type is Chunked

I need to get content-length from response header but it seems that content-length header is missing due to chunked Transfer Encoding. Is there anyway to get the content-length for Transfer-Encoding type

Answered by DTS Engineer in 679755022

Is there anyway to get the Content-Length for Transfer-Encoding type

No.

NSURLSession should return this header if the server provided it but the HTTP spec requires the server to not provide it when using the chunked transfer encoding.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Accepted Answer

Is there anyway to get the Content-Length for Transfer-Encoding type

No.

NSURLSession should return this header if the server provided it but the HTTP spec requires the server to not provide it when using the chunked transfer encoding.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Thank you. Is there any other transfer encoding recommended so that I can get content-length?

Accepted Answer

Is there any other transfer encoding recommended so that I can get Content-Length?

Yes, the identity transfer encoding. However, you can’t control this from the client; the transfer encoding is determined by the server [1].

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] Well, technically it’s a negotiation but clients are required to support the chunked encoding and thus you can’t stop the server from choosing that.

"content-length" unavailable when Transfer-Encoding type is Chunked
 
 
Q