FLEXNetworkRecorder.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //
  2. // FLEXNetworkRecorder.h
  3. // Flipboard
  4. //
  5. // Created by Ryan Olson on 2/4/15.
  6. // Copyright (c) 2015 Flipboard. 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. + (instancetype)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 with an "image", "video", or "audio" prefix.
  21. @property (nonatomic) BOOL shouldCacheMediaResponses;
  22. @property (nonatomic, copy) NSArray<NSString *> *hostBlacklist;
  23. // Accessing recorded network activity
  24. /// Array of FLEXNetworkTransaction objects ordered by start time with the newest first.
  25. - (NSArray<FLEXNetworkTransaction *> *)networkTransactions;
  26. /// The full response data IFF it hasn't been purged due to memory pressure.
  27. - (NSData *)cachedResponseBodyForTransaction:(FLEXNetworkTransaction *)transaction;
  28. /// Dumps all network transactions and cached response bodies.
  29. - (void)clearRecordedActivity;
  30. // Recording network activity
  31. /// Call when app is about to send HTTP request.
  32. - (void)recordRequestWillBeSentWithRequestID:(NSString *)requestID request:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse;
  33. /// Call when HTTP response is available.
  34. - (void)recordResponseReceivedWithRequestID:(NSString *)requestID response:(NSURLResponse *)response;
  35. /// Call when data chunk is received over the network.
  36. - (void)recordDataReceivedWithRequestID:(NSString *)requestID dataLength:(int64_t)dataLength;
  37. /// Call when HTTP request has finished loading.
  38. - (void)recordLoadingFinishedWithRequestID:(NSString *)requestID responseBody:(NSData *)responseBody;
  39. /// Call when HTTP request has failed to load.
  40. - (void)recordLoadingFailedWithRequestID:(NSString *)requestID error:(NSError *)error;
  41. /// Call to set the request mechanism anytime after recordRequestWillBeSent... has been called.
  42. /// This string can be set to anything useful about the API used to make the request.
  43. - (void)recordMechanism:(NSString *)mechanism forRequestID:(NSString *)requestID;
  44. @end