title: NSURLSession with custom authentication challenge?
body: <p>Our application makes use of RESTful service calls using <code>NSURLSession</code>.  The calls themselves are routed through a reverse proxy, to aide in session management, security, etc. on the backend.  The only problem we're having is related to authentication.  When a user attempts to access a protected resource -- either through a browser or a REST call -- and they are <em>not authenticated</em>, the reverse proxy displays an HTML login page.</p>
  
  <p>The problem is, we'd like to leverage <code>NSURLSession</code>'s ability to handle authentication challenges automatically.  However, <code>NSURLSession</code> is unable to recognize that we're getting back an authentication challenge, because no HTTP 401 or other error code is being returned to the client.  The reverse proxy sends back a 200, because the HTML was delivered successfully.  We're able to recognize that it is the login page by inspecting the HTML within the client, but we'd like to be able to handle the authentication using a custom <code>NSURLAuthenticationChallenge</code>, if at all possible, so that <code>NSURLSession</code> can retry requests after authentication is successful.</p>
  
  <p>Is there any way for us to recognize that we're getting back a login page within our <code>completionHandler</code> and tell <code>NSURLSession</code> that we're really getting back an authentication challenge?  Or does <code>NSURLSession</code> require that we receive back an HTTP error code (401, etc.)</p>