diff --git a/SDWebImage/SDWebImageDownloader.h b/SDWebImage/SDWebImageDownloader.h index c28d09a8..b75b69a2 100644 --- a/SDWebImage/SDWebImageDownloader.h +++ b/SDWebImage/SDWebImageDownloader.h @@ -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. * diff --git a/SDWebImage/SDWebImageDownloader.m b/SDWebImage/SDWebImageDownloader.m index 0f761261..fb3bd13a 100644 --- a/SDWebImage/SDWebImageDownloader.m +++ b/SDWebImage/SDWebImageDownloader.m @@ -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; - request.allHTTPHeaderFields = wself.HTTPHeaders; + 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;