Merge pull request #514 from crazytonyli/header-picking
Add HTTP header passing test to pick header for downloading request
This commit is contained in:
commit
75a76d983a
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue