SDWebImageDownloaderRequestModifier.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * This file is part of the SDWebImage package.
  3. * (c) Olivier Poitrey <rs@dailymotion.com>
  4. *
  5. * For the full copyright and license information, please view the LICENSE
  6. * file that was distributed with this source code.
  7. */
  8. #import <Foundation/Foundation.h>
  9. #import "SDWebImageCompat.h"
  10. typedef NSURLRequest * _Nullable (^SDWebImageDownloaderRequestModifierBlock)(NSURLRequest * _Nonnull request);
  11. /**
  12. This is the protocol for downloader request modifier.
  13. We can use a block to specify the downloader request modifier. But Using protocol can make this extensible, and allow Swift user to use it easily instead of using `@convention(block)` to store a block into context options.
  14. */
  15. @protocol SDWebImageDownloaderRequestModifier <NSObject>
  16. /// Modify the original URL request and return a new one instead. You can modify the HTTP header, cachePolicy, etc for this URL.
  17. /// @param request The original URL request for image loading
  18. /// @note If return nil, the URL request will be cancelled.
  19. - (nullable NSURLRequest *)modifiedRequestWithRequest:(nonnull NSURLRequest *)request;
  20. @end
  21. /**
  22. A downloader request modifier class with block.
  23. */
  24. @interface SDWebImageDownloaderRequestModifier : NSObject <SDWebImageDownloaderRequestModifier>
  25. /// Create the request modifier with block
  26. /// @param block A block to control modifier logic
  27. - (nonnull instancetype)initWithBlock:(nonnull SDWebImageDownloaderRequestModifierBlock)block;
  28. /// Create the request modifier with block
  29. /// @param block A block to control modifier logic
  30. + (nonnull instancetype)requestModifierWithBlock:(nonnull SDWebImageDownloaderRequestModifierBlock)block;
  31. @end
  32. /**
  33. A convenient request modifier to provide the HTTP request including HTTP Method, Headers and Body.
  34. */
  35. @interface SDWebImageDownloaderRequestModifier (Conveniences)
  36. /// Create the request modifier with HTTP Method.
  37. /// @param method HTTP Method, nil means to GET.
  38. /// @note This is for convenience, if you need code to control the logic, use block API instead.
  39. - (nonnull instancetype)initWithMethod:(nullable NSString *)method;
  40. /// Create the request modifier with HTTP Headers.
  41. /// @param headers HTTP Headers. Case insensitive according to HTTP/1.1(HTTP/2) standard. The headers will override the same fields from original request.
  42. /// @note This is for convenience, if you need code to control the logic, use block API instead.
  43. - (nonnull instancetype)initWithHeaders:(nullable NSDictionary<NSString *, NSString *> *)headers;
  44. /// Create the request modifier with HTTP Body.
  45. /// @param body HTTP Body.
  46. /// @note This is for convenience, if you need code to control the logic, use block API instead.
  47. - (nonnull instancetype)initWithBody:(nullable NSData *)body;
  48. /// Create the request modifier with HTTP Method, Headers and Body.
  49. /// @param method HTTP Method, nil means to GET.
  50. /// @param headers HTTP Headers. Case insensitive according to HTTP/1.1(HTTP/2) standard. The headers will override the same fields from original request.
  51. /// @param body HTTP Body.
  52. /// @note This is for convenience, if you need code to control the logic, use block API instead.
  53. - (nonnull instancetype)initWithMethod:(nullable NSString *)method headers:(nullable NSDictionary<NSString *, NSString *> *)headers body:(nullable NSData *)body;
  54. @end