Skip to content

Commit 597a70a

Browse files
committed
Add HTTP header filter to pick headers for downloading request
1 parent 9820caf commit 597a70a

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

SDWebImage/SDWebImageDownloader.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ typedef void(^SDWebImageDownloaderCompletedBlock)(UIImage *image, NSData *data,
5858

5959
+ (SDWebImageDownloader *)sharedDownloader;
6060

61+
/**
62+
* Set filter to pick headers for downloading image HTTP request.
63+
*
64+
* This block will be invoked for each downloading image request, returned
65+
* NSDictionary will be used as headers in corresponding HTTP request.
66+
*/
67+
@property (nonatomic, strong) NSDictionary *(^headersFilter)(NSURL *url, NSDictionary *headers);
68+
6169
/**
6270
* Set a value for a HTTP header to be appended to each download HTTP request.
6371
*

SDWebImage/SDWebImageDownloader.m

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,14 @@ - (NSInteger)maxConcurrentDownloads
120120
NSMutableURLRequest *request = [NSMutableURLRequest.alloc initWithURL:url cachePolicy:(options & SDWebImageDownloaderUseNSURLCache ? NSURLRequestUseProtocolCachePolicy : NSURLRequestReloadIgnoringLocalCacheData) timeoutInterval:15];
121121
request.HTTPShouldHandleCookies = NO;
122122
request.HTTPShouldUsePipelining = YES;
123-
request.allHTTPHeaderFields = wself.HTTPHeaders;
123+
if (wself.headersFilter)
124+
{
125+
request.allHTTPHeaderFields = wself.headersFilter(url, [wself.HTTPHeaders copy]);
126+
}
127+
else
128+
{
129+
request.allHTTPHeaderFields = wself.HTTPHeaders;
130+
}
124131
operation = [SDWebImageDownloaderOperation.alloc initWithRequest:request options:options progress:^(NSUInteger receivedSize, long long expectedSize)
125132
{
126133
if (!wself) return;

0 commit comments

Comments
 (0)