AFNetworking/AFNetworking — pull request #1511 by JacobOscarson (2013-10-17 12:56:06+00:00)
Title: Let the UIWebView extension handle binary responses

As I wrote about in #1499, the extension to `UIWebView`, `loadRequest:progress:success:failure:` seems to not handle binary responses very well. After looking a little bit closer at the code I'm now submitting this patch, which at least does what I want in my app. The new interface for the `success:` callback is now changed to try to load the response with `UIWebView loadData:MIMEType:textEncodingName:baseURL:` when a `nil` is returned.

I've also edited the docstring of `loadRequest:progress:success:failure:` to mention that any returned string will be entered to the `UIWebView` as HTML.

One caveat though: `.RTF` files are returned as `NSString`'s in the `operation.responseString` property in the code, and I'm not familiar enough with the rest of the code base to handle that case very gracefully. For now, I simply added a clause to the `if` statement that checks the result of the `success` / `operation.responseString` to crudely look for responses of MIME-type `'application/rtf'` and force them to enter the code path where binary values are handled. I'm aware that this isn't the most flexible nor elegant way of handling this case, maybe someone have a better suggestion?

Secondly I wasn't able to get the tests to run on my setup so I hope I'm not missing a test somewhere. I had a quick look but couldn't find any directly related to the `UIWebView` extensions, so I submitted anyways.