FLEXNetworkRecorder.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 presisted across launches of the app.
  19. @property (nonatomic, assign) 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, assign) BOOL shouldCacheMediaResponses;
  22. // Accessing recorded network activity
  23. /// Array of FLEXNetworkTransaction objects ordered by start time with the newest first.
  24. - (NSArray *)networkTransactions;
  25. /// The full response data IFF it hasn't been purged due to memory pressure.
  26. - (NSData *)cachedResponseBodyForTransaction:(FLEXNetworkTransaction *)transaction;
  27. /// Dumps all network transactions and cached response bodies.
  28. - (void)clearRecordedActivity;
  29. // Recording network activity
  30. /// Call when app is about to send HTTP request.
  31. - (void)recordRequestWillBeSentWithRequestID:(NSString *)requestID request:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse;
  32. /// Call when HTTP response is available.
  33. - (void)recordResponseReceivedWithRequestID:(NSString *)requestID response:(NSURLResponse *)response;
  34. /// Call when data chunk is received over the network.
  35. - (void)recordDataReceivedWithRequestID:(NSString *)requestID dataLength:(int64_t)dataLength;
  36. /// Call when HTTP request has finished loading.
  37. - (void)recordLoadingFinishedWithRequestID:(NSString *)requestID responseBody:(NSData *)responseBody;
  38. /// Call when HTTP request has failed to load.
  39. - (void)recordLoadingFailedWithRequestID:(NSString *)requestID error:(NSError *)error;
  40. /// Call to set the request mechanism anytime after recordRequestWillBeSent... has been called.
  41. /// This string can be set to anything useful about the API used to make the request.
  42. - (void)recordMechanism:(NSString *)mechanism forRequestID:(NSString *)requestID;
  43. @end