Merge pull request #514 from crazytonyli/header-picking

Add HTTP header passing test to pick header for downloading request
This commit is contained in:
Olivier Poitrey 2013-11-24 22:28:19 -08:00
commit 75a76d983a
2 changed files with 16 additions and 1 deletions

View File

@ -69,6 +69,14 @@ typedef void(^SDWebImageDownloaderCompletedBlock)(UIImage *image, NSData *data,
+ (SDWebImageDownloader *)sharedDownloader;
/**
* Set filter to pick headers for downloading image HTTP request.
*
* This block will be invoked for each downloading image request, returned
* NSDictionary will be used as headers in corresponding HTTP request.
*/
@property (nonatomic, strong) NSDictionary *(^headersFilter)(NSURL *url, NSDictionary *headers);
/**
* Set a value for a HTTP header to be appended to each download HTTP request.
*

View File

@ -120,7 +120,14 @@ static NSString *const kCompletedCallbackKey = @"completed";
NSMutableURLRequest *request = [NSMutableURLRequest.alloc initWithURL:url cachePolicy:(options & SDWebImageDownloaderUseNSURLCache ? NSURLRequestUseProtocolCachePolicy : NSURLRequestReloadIgnoringLocalCacheData) timeoutInterval:15];
request.HTTPShouldHandleCookies = (options & SDWebImageDownloaderHandleCookies);
request.HTTPShouldUsePipelining = YES;
if (wself.headersFilter)
{
request.allHTTPHeaderFields = wself.headersFilter(url, [wself.HTTPHeaders copy]);
}
else
{
request.allHTTPHeaderFields = wself.HTTPHeaders;
}
operation = [SDWebImageDownloaderOperation.alloc initWithRequest:request options:options progress:^(NSUInteger receivedSize, long long expectedSize)
{
if (!wself) return;