FSNetworking
FSNetworking copied to clipboard
How to set/get the timeout on a connection?
Is there a default value? I skimmed the source, but couldn't find any instance of "timeout".
Currently it just uses the default value for NSURLConnection. FSNConnection does not expose the NSMutableURLRequest on which you would set the timeout, as well as cache policy and some other potentially useful variables. This should probably be enhanced.
I haven't thought about the design in very much detail, but there are two ways i can see accomplishing this:
1: just add more properties to NSURLConnection that get passed on to the internal NSMutableURLRequest. The advantages are:
- simplicity of interface, easy to implement;
- we could potentially enforce a "no property mutations after connection starts" rule (using custom setters for those properties) that might help catch programmer errors.
2: add an NSMutableURLRequest urlRequest property to FSNConnection, and then refactor the +(id)with… constructor so that by default it creates a request with the argument url.
- maintainers would not have to be responsible for providing public properties to expose all the features (including future ones) that NSMutableURLRequest provides.
- there are potentially more ways to get unexpected behavior, e.g. setting a property on the request object that then gets silently overwritten in makeNSURLRequest (which would probably deserve to be renamed under this approach).
Thoughts?
My vote would be for option 1, more properties. There's already a bunch of time-related properties (startTime
, challengeInterval
, etc), so it doesn't feel incongruous to add more. Also, +(id)withUrl...
takes enough params as it is. Lastly, I didn't even have to know there's a NSMutableURLRequest
underneath, and so far the only knob I've felt the need to tweak was the timeout, so all the other request properties and options are distracting.
My 2 cents.