Skip to content

Commit 75a76d9

Browse files
author
Olivier Poitrey
committed
Merge pull request SDWebImage#514 from crazytonyli/header-picking
Add HTTP header passing test to pick header for downloading request
2 parents 1e20c3b + 597a70a commit 75a76d9

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
@@ -69,6 +69,14 @@ typedef void(^SDWebImageDownloaderCompletedBlock)(UIImage *image, NSData *data,
6969

7070
+ (SDWebImageDownloader *)sharedDownloader;
7171

72+
/**
73+
* Set filter to pick headers for downloading image HTTP request.
74+
*
75+
* This block will be invoked for each downloading image request, returned
76+
* NSDictionary will be used as headers in corresponding HTTP request.
77+
*/
78+
@property (nonatomic, strong) NSDictionary *(^headersFilter)(NSURL *url, NSDictionary *headers);
79+
7280
/**
7381
* Set a value for a HTTP header to be appended to each download HTTP request.
7482
*

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 = (options & SDWebImageDownloaderHandleCookies);
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)