Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Timeout property for AFHTTPClient #576

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions AFNetworking/AFHTTPClient.h
Expand Up @@ -121,6 +121,11 @@ typedef enum {
*/
@property (readonly, nonatomic) NSOperationQueue *operationQueue;

/**
* Timout for requests.
*/
@property (nonatomic, assign) NSTimeInterval timeoutInterval;

/**
The reachability status from the device to the current `baseURL` of the `AFHTTPClient`.

Expand Down
5 changes: 5 additions & 0 deletions AFNetworking/AFHTTPClient.m
Expand Up @@ -219,6 +219,7 @@ @implementation AFHTTPClient
@synthesize registeredHTTPOperationClassNames = _registeredHTTPOperationClassNames;
@synthesize defaultHeaders = _defaultHeaders;
@synthesize operationQueue = _operationQueue;
@synthesize timeoutInterval = _timeoutInterval;
#ifdef _SYSTEMCONFIGURATION_H
@synthesize networkReachability = _networkReachability;
@synthesize networkReachabilityStatus = _networkReachabilityStatus;
Expand Down Expand Up @@ -427,6 +428,10 @@ - (NSMutableURLRequest *)requestWithMethod:(NSString *)method
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
[request setHTTPMethod:method];
[request setAllHTTPHeaderFields:self.defaultHeaders];

if (self.timeoutInterval > 0) {
[request setTimeoutInterval:self.timeoutInterval];
}

if (parameters) {
if ([method isEqualToString:@"GET"] || [method isEqualToString:@"HEAD"] || [method isEqualToString:@"DELETE"]) {
Expand Down