FLEXNetworkRecorder.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //
  2. // FLEXNetworkRecorder.h
  3. // Flipboard
  4. //
  5. // Created by Ryan Olson on 2/4/15.
  6. // Copyright (c) 2020 FLEX Team. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. // Notifications posted when the record is updated
  10. extern NSString *const kFLEXNetworkRecorderNewTransactionNotification;
  11. extern NSString *const kFLEXNetworkRecorderTransactionUpdatedNotification;
  12. extern NSString *const kFLEXNetworkRecorderUserInfoTransactionKey;
  13. extern NSString *const kFLEXNetworkRecorderTransactionsClearedNotification;
  14. @class FLEXNetworkTransaction;
  15. @interface FLEXNetworkRecorder : NSObject
  16. /// In general, it only makes sense to have one recorder for the entire application.
  17. @property (nonatomic, readonly, class) FLEXNetworkRecorder *defaultRecorder;
  18. /// Defaults to 25 MB if never set. Values set here are persisted across launches of the app.
  19. @property (nonatomic) NSUInteger responseCacheByteLimit;
  20. /// If NO, the recorder not cache will not cache response for content types
  21. /// with an "image", "video", or "audio" prefix.
  22. @property (nonatomic) BOOL shouldCacheMediaResponses;
  23. @property (nonatomic) NSMutableArray<NSString *> *hostBlacklist;
  24. /// Call this after adding to or setting the \c hostBlacklist to remove blacklisted transactions
  25. - (void)clearBlacklistedTransactions;
  26. /// Call this to save the blacklist to the disk to be loaded next time
  27. - (void)synchronizeBlacklist;
  28. // Accessing recorded network activity
  29. /// Array of FLEXNetworkTransaction objects ordered by start time with the newest first.
  30. - (NSArray<FLEXNetworkTransaction *> *)networkTransactions;
  31. /// The full response data IFF it hasn't been purged due to memory pressure.
  32. - (NSData *)cachedResponseBodyForTransaction:(FLEXNetworkTransaction *)transaction;
  33. /// Dumps all network transactions and cached response bodies.
  34. - (void)clearRecordedActivity;
  35. // Recording network activity
  36. /// Call when app is about to send HTTP request.
  37. - (void)recordRequestWillBeSentWithRequestID:(NSString *)requestID
  38. request:(NSURLRequest *)request
  39. redirectResponse:(NSURLResponse *)redirectResponse;
  40. /// Call when HTTP response is available.
  41. - (void)recordResponseReceivedWithRequestID:(NSString *)requestID response:(NSURLResponse *)response;
  42. /// Call when data chunk is received over the network.
  43. - (void)recordDataReceivedWithRequestID:(NSString *)requestID dataLength:(int64_t)dataLength;
  44. /// Call when HTTP request has finished loading.
  45. - (void)recordLoadingFinishedWithRequestID:(NSString *)requestID responseBody:(NSData *)responseBody;
  46. /// Call when HTTP request has failed to load.
  47. - (void)recordLoadingFailedWithRequestID:(NSString *)requestID error:(NSError *)error;
  48. /// Call to set the request mechanism anytime after recordRequestWillBeSent... has been called.
  49. /// This string can be set to anything useful about the API used to make the request.
  50. - (void)recordMechanism:(NSString *)mechanism forRequestID:(NSString *)requestID;
  51. @end