From d08d63fadd7db748e0473661a509bf6f48d32735 Mon Sep 17 00:00:00 2001 From: Dan Peleg Date: Mon, 18 Nov 2013 17:18:58 -0500 Subject: [PATCH] Added SDWebImageOption to enable Cookies Handling. --- SDWebImage/SDWebImageDownloader.h | 7 ++++++- SDWebImage/SDWebImageDownloader.m | 2 +- SDWebImage/SDWebImageManager.h | 7 ++++++- SDWebImage/SDWebImageManager.m | 1 + 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/SDWebImage/SDWebImageDownloader.h b/SDWebImage/SDWebImageDownloader.h index b248730b..c28d09a8 100644 --- a/SDWebImage/SDWebImageDownloader.h +++ b/SDWebImage/SDWebImageDownloader.h @@ -28,7 +28,12 @@ typedef enum * In iOS 4+, continue the download of the image if the app goes to background. This is achieved by asking the system for * extra time in background to let the request finish. If the background task expires the operation will be cancelled. */ - SDWebImageDownloaderContinueInBackground = 1 << 4 + SDWebImageDownloaderContinueInBackground = 1 << 4, + /** + * Handles cookies stored in NSHTTPCookieStore by setting + * NSMutableURLRequest.HTTPShouldHandleCookies = YES; + */ + SDWebImageDownloaderHandleCookies = 1 << 5 } SDWebImageDownloaderOptions; diff --git a/SDWebImage/SDWebImageDownloader.m b/SDWebImage/SDWebImageDownloader.m index 063056fe..0f761261 100644 --- a/SDWebImage/SDWebImageDownloader.m +++ b/SDWebImage/SDWebImageDownloader.m @@ -118,7 +118,7 @@ static NSString *const kCompletedCallbackKey = @"completed"; { // In order to prevent from potential duplicate caching (NSURLCache + SDImageCache) we disable the cache for image requests if told otherwise NSMutableURLRequest *request = [NSMutableURLRequest.alloc initWithURL:url cachePolicy:(options & SDWebImageDownloaderUseNSURLCache ? NSURLRequestUseProtocolCachePolicy : NSURLRequestReloadIgnoringLocalCacheData) timeoutInterval:15]; - request.HTTPShouldHandleCookies = NO; + request.HTTPShouldHandleCookies = (options & SDWebImageDownloaderHandleCookies); request.HTTPShouldUsePipelining = YES; request.allHTTPHeaderFields = wself.HTTPHeaders; operation = [SDWebImageDownloaderOperation.alloc initWithRequest:request options:options progress:^(NSUInteger receivedSize, long long expectedSize) diff --git a/SDWebImage/SDWebImageManager.h b/SDWebImage/SDWebImageManager.h index b54af25e..b6df499a 100644 --- a/SDWebImage/SDWebImageManager.h +++ b/SDWebImage/SDWebImageManager.h @@ -46,7 +46,12 @@ typedef enum * In iOS 4+, continue the download of the image if the app goes to background. This is achieved by asking the system for * extra time in background to let the request finish. If the background task expires the operation will be cancelled. */ - SDWebImageContinueInBackground = 1 << 5 + SDWebImageContinueInBackground = 1 << 5, + /** + * Handles cookies stored in NSHTTPCookieStore by setting + * NSMutableURLRequest.HTTPShouldHandleCookies = YES; + */ + SDWebImageHandleCookies = 1 << 6 } SDWebImageOptions; typedef void(^SDWebImageCompletedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType); diff --git a/SDWebImage/SDWebImageManager.m b/SDWebImage/SDWebImageManager.m index 7f558a50..34193b6c 100644 --- a/SDWebImage/SDWebImageManager.m +++ b/SDWebImage/SDWebImageManager.m @@ -145,6 +145,7 @@ if (options & SDWebImageProgressiveDownload) downloaderOptions |= SDWebImageDownloaderProgressiveDownload; if (options & SDWebImageRefreshCached) downloaderOptions |= SDWebImageDownloaderUseNSURLCache; if (options & SDWebImageContinueInBackground) downloaderOptions |= SDWebImageDownloaderContinueInBackground; + if (options & SDWebImageHandleCookies) downloaderOptions |= SDWebImageDownloaderHandleCookies; if (image && options & SDWebImageRefreshCached) { // force progressive off if image already cached but forced refreshing