Skip to content

Commit 4884685

Browse files
author
Olivier Poitrey
committed
Merge pull request SDWebImage#591 from hsoi/downloader-timeout
Expose timeout property for the downloader.
2 parents 639aa64 + f66b8b8 commit 4884685

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

SDWebImage/SDWebImageDownloader.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ typedef void(^SDWebImageDownloaderCompletedBlock)(UIImage *image, NSData *data,
7373

7474
@property (readonly, nonatomic) NSUInteger currentDownloadCount;
7575

76+
77+
/**
78+
* The timeout value (in seconds) for the download operation. Default: 15.0.
79+
*/
80+
@property (assign, nonatomic) NSTimeInterval downloadTimeout;
81+
82+
7683
/**
7784
* Changes download operations execution order. Default value is `SDWebImageDownloaderFIFOExecutionOrder`.
7885
*/

SDWebImage/SDWebImageDownloader.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ - (id)init
7272
_URLCallbacks = NSMutableDictionary.new;
7373
_HTTPHeaders = [NSMutableDictionary dictionaryWithObject:@"image/webp,image/*;q=0.8" forKey:@"Accept"];
7474
_barrierQueue = dispatch_queue_create("com.hackemist.SDWebImageDownloaderBarrierQueue", DISPATCH_QUEUE_CONCURRENT);
75+
_downloadTimeout = 15.0;
7576
}
7677
return self;
7778
}
@@ -121,8 +122,13 @@ - (NSInteger)maxConcurrentDownloads
121122

122123
[self addProgressCallback:progressBlock andCompletedBlock:completedBlock forURL:url createCallback:^
123124
{
125+
NSTimeInterval timeoutInterval = wself.downloadTimeout;
126+
if (timeoutInterval == 0.0) {
127+
timeoutInterval = 15.0;
128+
}
129+
124130
// In order to prevent from potential duplicate caching (NSURLCache + SDImageCache) we disable the cache for image requests if told otherwise
125-
NSMutableURLRequest *request = [NSMutableURLRequest.alloc initWithURL:url cachePolicy:(options & SDWebImageDownloaderUseNSURLCache ? NSURLRequestUseProtocolCachePolicy : NSURLRequestReloadIgnoringLocalCacheData) timeoutInterval:15];
131+
NSMutableURLRequest *request = [NSMutableURLRequest.alloc initWithURL:url cachePolicy:(options & SDWebImageDownloaderUseNSURLCache ? NSURLRequestUseProtocolCachePolicy : NSURLRequestReloadIgnoringLocalCacheData) timeoutInterval:timeoutInterval];
126132
request.HTTPShouldHandleCookies = (options & SDWebImageDownloaderHandleCookies);
127133
request.HTTPShouldUsePipelining = YES;
128134
if (wself.headersFilter)

0 commit comments

Comments
 (0)