Ok, I've figured it out. I used
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
NSDictionary *responseHeaders = ((NSHTTPURLResponse *)response).allHeaderFields;
NSLog(@"headers: %@", responseHeaders.description);
}
this method to figure out the headers that my iOS application was receiving, and I compared them with the headers that curl printed when connecting to the same URL. Turns out, there was a discrepancy between the headers that curl showed and that Objective-C did. Admittedly, it boggles my mind a lot, and I have no idea why that would happen, but I found a solution:
ob_start('scAPIHandler');
function scAPIHandler($buffer){
header('Custom-Content-Length: '.strlen($buffer));
return $buffer;
}
The Custom-Content-Length did appear in Objective-C, and I simply took my custom header
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
self.expectedContentLength = response.expectedContentLength;
self.receivedData.length = 0;
NSDictionary *responseHeaders = ((NSHTTPURLResponse *)response).allHeaderFields;
if(self.expectedContentLength < 0){
// take my own header
NSString *actualContentLength = responseHeaders[@"Custom-Content-Length"];
if(actualContentLength && actualContentLength.length > 0){
self.expectedContentLength = actualContentLength.longLongValue;
}
}
}
and overwrote the expected content length.