FLEXNetworkRecorder.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. @class FLEXNetworkTransaction;
  14. @interface FLEXNetworkRecorder : NSObject
  15. /// In general, it only makes sense to have one recorder for the entire application.
  16. + (instancetype)defaultRecorder;
  17. /// Defaults to 25 MB if never set. Values set here are presisted across launches of the app.
  18. @property (nonatomic, assign) NSUInteger responseCacheByteLimit;
  19. // Accessing recorded network activity
  20. /// Array of FLEXNetworkTransaction objects ordered by start time with the newest first.
  21. - (NSArray *)networkTransactions;
  22. /// The full response data IFF it hasn't been purged due to memory pressure.
  23. - (NSData *)cachedResponseBodyForTransaction:(FLEXNetworkTransaction *)transaction;
  24. // Recording network activity
  25. /// Call when app is about to send HTTP request.
  26. /// This method must be called for each recorded reqeust. Prior to this call, no information will be recorded for the request.
  27. - (void)recordRequestWillBeSentWithRequestId:(NSString *)requestId request:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse requestMechanism:(NSString *)mechanism;
  28. /// Call when HTTP response is available.
  29. - (void)recordResponseReceivedWithRequestId:(NSString *)requestId response:(NSURLResponse *)response;
  30. /// Call when data chunk is received over the network.
  31. - (void)recordDataReceivedWithRequestId:(NSString *)requestId dataLength:(int64_t)dataLength;
  32. /// Call when HTTP request has finished loading.
  33. - (void)recordLoadingFinishedWithRequestId:(NSString *)requestId responseBody:(NSData *)responseBody;
  34. /// Call when HTTP request has failed to load.
  35. - (void)recordLoadingFailedWithRequestId:(NSString *)requestId error:(NSError *)error;
  36. @end