Просмотр исходного кода

Added configuration to filter out network requests for particular hosts from being recorded

Colin Humber лет назад: 9
Родитель
Сommit
b8c6175193

+ 6 - 0
Classes/FLEXManager.h

@@ -30,6 +30,12 @@
 /// The response cache uses an NSCache, so it may purge prior to hitting the limit when the app is under memory pressure.
 @property (nonatomic, assign) NSUInteger networkResponseCacheByteLimit;
 
+/// Requests whose host ends with one of the blacklisted entries in this array will be not be recorded (eg. google.com).
+/// Wildcard or subdomain entries are not required (eg. google.com will match any subdomain under google.com).
+/// Useful to remove requests that are typically noisy, such as analytics requests that you aren't interested in tracking.
+@property (nonatomic, copy) NSArray<NSString *> *networkRequestHostBlacklist;
+
+
 #pragma mark - Keyboard Shortcuts
 
 /// Simulator keyboard shortcuts are enabled by default.

+ 8 - 0
Classes/Manager/FLEXManager.m

@@ -115,6 +115,14 @@
     [[FLEXNetworkRecorder defaultRecorder] setResponseCacheByteLimit:networkResponseCacheByteLimit];
 }
 
+- (void)setNetworkRequestHostBlacklist:(NSArray<NSString *> *)networkRequestHostBlacklist {
+    [FLEXNetworkRecorder defaultRecorder].hostBlacklist = networkRequestHostBlacklist;
+}
+
+- (NSArray<NSString *> *)hostBlacklist {
+    return [FLEXNetworkRecorder defaultRecorder].hostBlacklist;
+}
+
 #pragma mark - FLEXWindowEventDelegate
 
 - (BOOL)shouldHandleTouchAtPoint:(CGPoint)pointInWindow

+ 3 - 0
Classes/Network/FLEXNetworkRecorder.h

@@ -27,6 +27,9 @@ extern NSString *const kFLEXNetworkRecorderTransactionsClearedNotification;
 /// If NO, the recorder not cache will not cache response for content types with an "image", "video", or "audio" prefix.
 @property (nonatomic, assign) BOOL shouldCacheMediaResponses;
 
+@property (nonatomic, copy) NSArray<NSString *> *hostBlacklist;
+
+
 // Accessing recorded network activity
 
 /// Array of FLEXNetworkTransaction objects ordered by start time with the newest first.

+ 6 - 0
Classes/Network/FLEXNetworkRecorder.m

@@ -104,6 +104,12 @@ NSString *const kFLEXNetworkRecorderResponseCacheLimitDefaultsKey = @"com.flex.r
 
 - (void)recordRequestWillBeSentWithRequestID:(NSString *)requestID request:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse
 {
+    for (NSString *host in self.hostBlacklist) {
+        if ([request.URL.host hasSuffix:host]) {
+            return;
+        }
+    }
+    
     NSDate *startDate = [NSDate date];
 
     if (redirectResponse) {