Patch to fix a problem when using didReceiveData: delegate or dataReceivedBlock callback #319

wants to merge 7 commits into


None yet

3 participants


There is a problem when processing data using callbacks/delegates whereby the callback receives the body of a 401/407 response, and there is no way to tell from the callback whether the data is from the initial 40x response or from a subsequent response. This means if you are using a streaming parser with ASIHTTPRequest, you will get garbage before the actual data.

You cannot check the response status code, response headers, or any other part of the request inside the block because the values may have changed between the time the data was received and when the callback happens. The passOnReceivedData callback is enqueued on the main thread and execution is not blocked, so the callback can happen much later, after the request has successfully retried and looks like it was successful.

My patch simply disables the data callbacks when authentication is needed, so the 40x response is simply added to the rawResponseData buffer as it would be if there were no callbacks defined. Considering it is not possible with the current interface to figure out which request the data came from, the code as it stands is not useful anyway. With the patch, you can still get the 40x body through the standard interfaces if you need to access it.

I think this approach is better than changing the callback interface to include additional information like response status code, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment