AFNetworking/AFNetworking — pull request #139 by mattt (2011-12-04 09:55:20+00:00)
Title: Add Authentication Challenge Callback Block to AFURLConnectionOperation

Having received several questions relating to handling authentication challenges, I've come to the opinion that it would be useful and reasonable to add a mechanism to set that behavior without subclassing.

In this branch, `AFURLConnectionOperation` gets the following method:

```objective-c
- (void)setAuthenticationChallengeBlock:(void (^)(NSURLConnection *connection, NSURLAuthenticationChallenge *challenge))block;
```

This block provides an equivalent interface to the normal delegate method, allowing the user to customize the behavior to exactly the same capacity as overriding in subclass.

My primary concern I have is to make sure that the added implementation of `connection:didReceiveAuthenticationChallenge:` accurately matches the behavior of the default behavior for when the delegate does not implement the method. Quoth Apple:

> If the delegate does not implement this method the default implementation is used. If a valid credential for the request is provided as part of the URL, or is available from the NSURLCredentialStorage the [challenge sender] is sent a useCredential:forAuthenticationChallenge: with the credential. If the challenge has no credential or the credentials fail to authorize access, then continueWithoutCredentialForAuthenticationChallenge: is sent to [challenge sender] instead.

I would _love_ to be able to just use that default implementation, but I can't exactly call `super`, and I need to implement it at least as much as to pass in the callback block.

Does this look reasonable? Am I missing anything, or do you have any suggestions / requests?