title: Should didReceiveResponse always be called for NSURLSessionUploadTasks with custom delegates?
body: <p>I'm investigating using NSURLSessionUploadTasks to manage the background uploading of a few files. The session is created using:</p>
  
  <pre><code>_urlsession = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration backgroundSessionConfiguration:identifier] delegate:self delegateQueue:nil];
  </code></pre>
  
  <p>This is created within a class that conforms to <code>URLSessionDataTaskDelegate</code>, and specifically defines:</p>
  
  <pre><code>– URLSession:dataTask:didReceiveResponse:completionHandler:
  – URLSession:dataTask:didBecomeDownloadTask:
  – URLSession:dataTask:didReceiveData:
  </code></pre>
  
  <p>And logs to the console each time one of these delegates is called.</p>
  
  <p>Then, an upload task is created with the following code:</p>
  
  <pre><code>NSString *urlString = [NSString stringWithFormat:@"%@%@?filename=%@", HOST, UPLOAD_PATH, filename];
  NSMutableURLRequest *attachmentUploadRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]];
  attachmentUploadRequest.HTTPMethod = @"POST";
  [attachmentUploadRequest addValue:@"application/binary" forHTTPHeaderField:@"Content-Type"];
  
  NSURLSessionTask* task = [_urlsession uploadTaskWithRequest:attachmentUploadRequest fromFile:filePath];
  task.taskDescription = 'upload';
  </code></pre>
  
  <p>However, the sequence of delegate callbacks that I get is not as expected:</p>
  
  <pre><code>URLSession:didReceiveChallenge:completionHandler:]:196: Respond with &lt;NSURLCredential: 0x1cf4fe00&gt;:
  URLSession:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:]:282: Task 'upload' sent 32768 bytes
  URLSession:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:]:282: Task 'upload' sent 48150 bytes
  URLSession:dataTask:didReceiveData:]:222: Task 'upload' got some data:
  </code></pre>
  
  <p>Notably, the body data is sent, as expected, but then it switches immediately to <code>didReceiveData</code> delegate callbacks, with no <code>didReceiveResponse</code> callback beforehand. This is an unexpected behavior for me: I'd expected to receive information about the response so that I can properly set up data, or better yet, convert the task to a download task to save the response to a file. </p>
  
  <p>If the upload task is submitted in a default URL session, then didReceiveResponse is called, and I can successfully convert the task to a background download task. </p>
  
  <p>I can't find any indications in Apple's documentation for whether or not <code>didReceiveResponse</code> should be called for <code>NSURLSessionUploadTask</code>s that are in the background. It <em>seems</em> that they should: the documentation for <code>NSURLSessionUploadTask</code> indicates that it is a subclass of <code>NSURLSessionDataTask</code> with small modifications in behavior, but neither of the listed differences involves not sending the <code>didReceiveResponse</code> callback. None of the background-session-specific docs mention this limitation. </p>
  
  <p>Is this a bug, or have a missed/misinterpreted some piece of the documentation that explain that upload tasks in the background do not call <code>didReceiveResponse</code>?</p>