views:

71

answers:

1

I have an app that uses ASI-HTTP-Request for large files, and I had a tester recently note that they wer observing very long loading delays that should be manifesting as timeouts. I have delegate methods wired up for request failures, but these didn't seem to be happening.

I poured through their documentation but didn't see anything specific.

+2  A: 

In ASIHTTPRequest.m, look in the -checkRequestStatus method.

When a timeout occurs, the request fails with an ASIRequestTimedOutError error type:

[self failWithError:ASIRequestTimedOutError];

So you should be able to check the error returned in the delegate's -requestFailed: method:

- (void)requestFailed:(ASIHTTPRequest *)request {
    NSLog(@"Error: %@",[[request error] localizedDescription]);
}

It's a good idea to read through the source to get a rough feel for how things work. The documentation is great, but not always in sync with the source code.

Alex Reynolds
Thanks. Not knowing much about HTTP itself... I would ask this... if I have a file that is 5MB, and my request timeout is set to 10 seconds, and in 10 seconds it only loads say... 3MB... does that qualify as a timeout?
Jasconius
No, a timeout begins after no data comes in, between chunks. If it takes 10 seconds to download 3MB, and then the request waits, and waits, and waits, and no more data comes in... that's when the timeout timer starts. So in that example, it would be 20 seconds from the start of the request until the timeout error.
Alex Reynolds
How then would I say "ok, even if data comes in, this is taking a stupidly long time"... other than just making my own NSTimer... which I can do, just wondering if ASI gives me a built-in solution.
Jasconius
I can't see any built-in, but instead of making your own `NSTimer` instance you could easily tap into existing values in `ASIHTTPRequest`, continuously summing the `secondsSinceLastActivity` property to generate a custom `overallActivityTime` property. In `-checkRequestStatus` you could fail with your own custom error if `overallActivityTime` is above some preset threshold.
Alex Reynolds