From 484f6f422c8f3e2b480ef42d65b30cacac0cab23 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Fri, 24 Apr 2020 12:19:51 +0800 Subject: [PATCH] Add the only headers arg convenience initializer --- .../Core/SDWebImageDownloaderRequestModifier.h | 14 ++++++-------- .../Core/SDWebImageDownloaderRequestModifier.m | 9 ++++----- .../Core/SDWebImageDownloaderResponseModifier.h | 14 ++++++-------- .../Core/SDWebImageDownloaderResponseModifier.m | 9 ++++----- 4 files changed, 20 insertions(+), 26 deletions(-) diff --git a/SDWebImage/Core/SDWebImageDownloaderRequestModifier.h b/SDWebImage/Core/SDWebImageDownloaderRequestModifier.h index 016ef309..8928cf76 100644 --- a/SDWebImage/Core/SDWebImageDownloaderRequestModifier.h +++ b/SDWebImage/Core/SDWebImageDownloaderRequestModifier.h @@ -39,18 +39,16 @@ typedef NSURLRequest * _Nullable (^SDWebImageDownloaderRequestModifierBlock)(NSU */ @interface SDWebImageDownloaderHTTPRequestModifier : NSObject +/// Create the request modifier with HTTP Headers +/// @param headers HTTP Headers. Case insensitive according to HTTP/1.1(HTTP/2) standard. The headers will overide the same fileds from original request. +/// @note This is for convenience, if you need code to control the logic, use `SDWebImageDownloaderRequestModifier` instead +- (nonnull instancetype)initWithHeaders:(nullable NSDictionary *)headers; + /// Create the request modifier with HTTP Method, Headers and Body /// @param method HTTP Method, nil means to GET. /// @param headers HTTP Headers. Case insensitive according to HTTP/1.1(HTTP/2) standard. The headers will overide the same fileds from original request. /// @param body HTTP Body /// @note This is for convenience, if you need code to control the logic, use `SDWebImageDownloaderRequestModifier` instead -- (nonnull instancetype)initWithMethod:(nullable NSString *)method headers:(nullable NSDictionary *)headers body:(nullable NSData *)body; - -/// Create the request modifier with HTTP Method, Headers and Body -/// @param method HTTP Method, nil means to GET. -/// @param headers HTTP Headers. Case insensitive according to HTTP/1.1(HTTP/2) standard. The headers will overide the same fileds from SDWebImageDownloader global configuration. -/// @param body HTTP Body -/// @note This is for convenience, if you need code to control the logic, use `SDWebImageDownloaderRequestModifier` instead -+ (nonnull instancetype)requestModifierWithMethod:(nullable NSString *)method headers:(nullable NSDictionary *)headers body:(nullable NSData *)body; +- (nonnull instancetype)initWithMethod:(nullable NSString *)method headers:(nullable NSDictionary *)headers body:(nullable NSData *)body NS_DESIGNATED_INITIALIZER; @end diff --git a/SDWebImage/Core/SDWebImageDownloaderRequestModifier.m b/SDWebImage/Core/SDWebImageDownloaderRequestModifier.m index f80db2e9..8ce2c893 100644 --- a/SDWebImage/Core/SDWebImageDownloaderRequestModifier.m +++ b/SDWebImage/Core/SDWebImageDownloaderRequestModifier.m @@ -48,6 +48,10 @@ @implementation SDWebImageDownloaderHTTPRequestModifier +- (instancetype)initWithHeaders:(NSDictionary *)headers { + return [self initWithMethod:nil headers:headers body:nil]; +} + - (instancetype)initWithMethod:(NSString *)method headers:(NSDictionary *)headers body:(NSData *)body { self = [super init]; if (self) { @@ -58,11 +62,6 @@ return self; } -+ (instancetype)requestModifierWithMethod:(NSString *)method headers:(NSDictionary *)headers body:(NSData *)body { - SDWebImageDownloaderHTTPRequestModifier *requestModifier = [[SDWebImageDownloaderHTTPRequestModifier alloc] initWithMethod:method headers:headers body:body]; - return requestModifier; -} - - (NSURLRequest *)modifiedRequestWithRequest:(NSURLRequest *)request { NSMutableURLRequest *mutableRequest = [request mutableCopy]; mutableRequest.HTTPMethod = self.method; diff --git a/SDWebImage/Core/SDWebImageDownloaderResponseModifier.h b/SDWebImage/Core/SDWebImageDownloaderResponseModifier.h index 60b46020..1032f464 100644 --- a/SDWebImage/Core/SDWebImageDownloaderResponseModifier.h +++ b/SDWebImage/Core/SDWebImageDownloaderResponseModifier.h @@ -39,18 +39,16 @@ typedef NSURLResponse * _Nullable (^SDWebImageDownloaderResponseModifierBlock)(N */ @interface SDWebImageDownloaderHTTPResponseModifier : NSObject +/// Create the response modifier with HTTP Headers. Status code defaults to 200. +/// @param headers HTTP Headers. Case insensitive according to HTTP/1.1(HTTP/2) standard. The headers will overide the same fileds from original response. +/// @note This is for convenience, if you need code to control the logic, use `SDWebImageDownloaderResponseModifier` instead +- (nonnull instancetype)initWithHeaders:(nullable NSDictionary *)headers; + /// Create the response modifier with HTTP Version, Status Code and Headers /// @param version HTTP Version, nil means "HTTP/1.1" /// @param statusCode HTTP Status Code /// @param headers HTTP Headers. Case insensitive according to HTTP/1.1(HTTP/2) standard. The headers will overide the same fileds from original response. /// @note This is for convenience, if you need code to control the logic, use `SDWebImageDownloaderResponseModifier` instead -- (nonnull instancetype)initWithVersion:(nullable NSString *)version statusCode:(NSInteger)statusCode headers:(nullable NSDictionary *)headers; - -/// Create the response modifier with HTTP Version, Status Code and Headers -/// @param version HTTP Version, nil means "HTTP/1.1". See available value in CFNetwork like `kCFHTTPVersion1_1`. -/// @param statusCode HTTP Status Code -/// @param headers HTTP Headers. Case insensitive according to HTTP/1.1(HTTP/2) standard. The headers will overide the same fileds from original response. -/// @note This is for convenience, if you need code to control the logic, use `SDWebImageDownloaderResponseModifier` instead -+ (nonnull instancetype)responseModifierWithVersion:(nullable NSString *)version statusCode:(NSInteger)statusCode headers:(nullable NSDictionary *)headers; +- (nonnull instancetype)initWithVersion:(nullable NSString *)version statusCode:(NSInteger)statusCode headers:(nullable NSDictionary *)headers NS_DESIGNATED_INITIALIZER; @end diff --git a/SDWebImage/Core/SDWebImageDownloaderResponseModifier.m b/SDWebImage/Core/SDWebImageDownloaderResponseModifier.m index 7388b83a..e38f5d41 100644 --- a/SDWebImage/Core/SDWebImageDownloaderResponseModifier.m +++ b/SDWebImage/Core/SDWebImageDownloaderResponseModifier.m @@ -49,6 +49,10 @@ @implementation SDWebImageDownloaderHTTPResponseModifier +- (instancetype)initWithHeaders:(NSDictionary *)headers { + return [self initWithVersion:nil statusCode:200 headers:headers]; +} + - (instancetype)initWithVersion:(NSString *)version statusCode:(NSInteger)statusCode headers:(NSDictionary *)headers { self = [super init]; if (self) { @@ -59,11 +63,6 @@ return self; } -+ (instancetype)responseModifierWithVersion:(NSString *)version statusCode:(NSInteger)statusCode headers:(NSDictionary *)headers { - SDWebImageDownloaderHTTPResponseModifier *responseModifier = [[SDWebImageDownloaderHTTPResponseModifier alloc] initWithVersion:version statusCode:statusCode headers:headers]; - return responseModifier; -} - - (NSURLResponse *)modifiedResponseWithResponse:(NSURLResponse *)response { if (![response isKindOfClass:NSHTTPURLResponse.class]) { return response;