FLEXNetworkRecorder.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. /// This method must be called for each recorded reqeust. Prior to this call, no information will be recorded for the request.
  32. - (void)recordRequestWillBeSentWithRequestId:(NSString *)requestId request:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse requestMechanism:(NSString *)mechanism;
  33. /// Call when HTTP response is available.
  34. - (void)recordResponseReceivedWithRequestId:(NSString *)requestId request:(NSURLRequest *)request response:(NSURLResponse *)response;
  35. /// Call when data chunk is received over the network.
  36. - (void)recordDataReceivedWithRequestId:(NSString *)requestId request:(NSURLRequest *)request dataLength:(int64_t)dataLength;
  37. /// Call when HTTP request has finished loading.
  38. - (void)recordLoadingFinishedWithRequestId:(NSString *)requestId request:(NSURLRequest *)request responseBody:(NSData *)responseBody;
  39. /// Call when HTTP request has failed to load.
  40. - (void)recordLoadingFailedWithRequestId:(NSString *)requestId request:(NSURLRequest *)request error:(NSError *)error;
  41. @end