KTVHTTPCacheImp.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. //
  2. // KTVHTTPCacheImp.h
  3. // KTVHTTPCache
  4. //
  5. // Created by Single on 2017/8/13.
  6. // Copyright © 2017年 Single. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. @class KTVHCDataReader;
  10. @class KTVHCDataLoader;
  11. @class KTVHCDataRequest;
  12. @class KTVHCDataCacheItem;
  13. @interface KTVHTTPCache : NSObject
  14. #pragma mark - HTTP Server
  15. /**
  16. * Start & Stop HTTP Server.
  17. */
  18. + (void)proxyStart:(NSError **)error;
  19. + (void)proxyStop;
  20. + (BOOL)proxyIsRunning;
  21. /**
  22. * Return the URL string for local server.
  23. */
  24. + (NSURL *)proxyURLWithOriginalURL:(NSURL *)URL;
  25. + (NSString *)proxyURLStringWithOriginalURLString:(NSString *)URLString;
  26. #pragma mark - Data Storage
  27. /**
  28. * If the content of the URL is finish cached, return the file path for the content. Otherwise return nil.
  29. */
  30. + (NSURL *)cacheCompleteFileURLIfExistedWithURL:(NSURL *)URL;
  31. + (NSString *)cacheCompleteFilePathIfExistedWithURLString:(NSString *)URLString;
  32. /**
  33. * Data Reader.
  34. */
  35. + (KTVHCDataReader *)cacheReaderWithRequest:(KTVHCDataRequest *)request;
  36. /**
  37. * Data Loader.
  38. */
  39. + (KTVHCDataLoader *)cacheLoaderWithRequest:(KTVHCDataRequest *)request;
  40. /**
  41. * Cache State.
  42. */
  43. + (void)cacheSetMaxCacheLength:(long long)maxCacheLength;
  44. + (long long)cacheMaxCacheLength;
  45. + (long long)cacheTotalCacheLength;
  46. /**
  47. * Cache Item.
  48. */
  49. + (KTVHCDataCacheItem *)cacheCacheItemWithURL:(NSURL *)URL;
  50. + (KTVHCDataCacheItem *)cacheCacheItemWithURLString:(NSString *)URLString;
  51. + (NSArray <KTVHCDataCacheItem *> *)cacheAllCacheItems;
  52. /**
  53. * Delete Cache.
  54. */
  55. + (void)cacheDeleteCacheWithURL:(NSURL *)URL;
  56. + (void)cacheDeleteCacheWithURLString:(NSString *)URLString;
  57. + (void)cacheDeleteAllCaches;
  58. #pragma mark - Token
  59. /**
  60. * URL Filter.
  61. *
  62. * High frequency call. Make it simple.
  63. */
  64. + (void)tokenSetURLFilter:(NSURL * (^)(NSURL * URL))URLFilter;
  65. #pragma mark - Download
  66. + (void)downloadSetTimeoutInterval:(NSTimeInterval)timeoutInterval;
  67. + (NSTimeInterval)downloadTimeoutInterval;
  68. /**
  69. * Whitelist Header Fields.
  70. */
  71. + (void)downloadSetWhitelistHeaderKeys:(NSArray <NSString *> *)whitelistHeaderKeys;
  72. + (NSArray <NSString *> *)downloadWhitelistHeaderKeys;
  73. /**
  74. * Additional Header Fields.
  75. */
  76. + (void)downloadSetAdditionalHeaders:(NSDictionary <NSString *, NSString *> *)additionalHeaders;
  77. + (NSDictionary <NSString *, NSString *> *)downloadAdditionalHeaders;
  78. /**
  79. * Default values: 'video/x', 'audio/x', 'application/mp4', 'application/octet-stream', 'binary/octet-stream'
  80. */
  81. + (void)downloadSetAcceptContentTypes:(NSArray <NSString *> *)acceptContentTypes;
  82. + (NSArray <NSString *> *)downloadAcceptContentTypes;
  83. /**
  84. * If the receive response's Content-Type not included in acceptContentTypes, this method will be called.
  85. * The return value of block to decide whether to continue to load resources. Otherwise the HTTP task will be rejected.
  86. */
  87. + (void)downloadSetUnsupportContentTypeFilter:(BOOL(^)(NSURL * URL, NSString * contentType))contentTypeFilter;
  88. #pragma mark - Log
  89. /**
  90. * Console & Record.
  91. */
  92. + (void)logAddLog:(NSString *)log;
  93. /**
  94. * DEBUG & RELEASE : Default is NO.
  95. */
  96. + (void)logSetConsoleLogEnable:(BOOL)consoleLogEnable;
  97. + (BOOL)logConsoleLogEnable;
  98. /**
  99. * DEBUG & RELEASE : Default is NO.
  100. */
  101. + (void)logSetRecordLogEnable:(BOOL)recordLogEnable;
  102. + (BOOL)logRecordLogEnable;
  103. + (NSString *)logRecordLogFilePath; // nullable
  104. + (void)logDeleteRecordLog;
  105. /**
  106. * Error
  107. */
  108. + (NSArray <NSError *> *)logAllErrors;
  109. + (NSError *)logLastError;
  110. @end