Authored by 孙凯

add 采用originalRequest review by hongmo

@@ -25,31 +25,31 @@ @@ -25,31 +25,31 @@
25 #pragma mark - 属性 25 #pragma mark - 属性
26 26
27 +(void)startTrack{ 27 +(void)startTrack{
28 - static dispatch_once_t onceToken;  
29 - dispatch_once(&onceToken, ^{  
30 - @try {  
31 - SEL selectors[] = {  
32 - //@selector(dataTaskWithRequest:completionHandler:),  
33 - //@selector(downloadTaskWithRequest:completionHandler:),  
34 - };  
35 -  
36 - for (NSUInteger index = 0; index < sizeof(selectors) / sizeof(SEL); ++index) {  
37 - SEL originalSelector = selectors[index];  
38 - SEL swizzledSelector = NSSelectorFromString([@"yher_" stringByAppendingString:NSStringFromSelector(originalSelector)]);  
39 - NSError *error = NULL;  
40 - [[self class] yh_swizzleMethod:originalSelector  
41 - withMethod:swizzledSelector  
42 - error:&error];  
43 - if (error) {  
44 - YHLog(@"Failed to swizzle: on UIControl. Details: %@", error);  
45 - error = NULL;  
46 - }  
47 - }  
48 -  
49 - } @catch (NSException *exception) {  
50 - YHLog(@"%@ error: %@", self, exception);  
51 - }  
52 - }); 28 +// static dispatch_once_t onceToken;
  29 +// dispatch_once(&onceToken, ^{
  30 +// @try {
  31 +// SEL selectors[] = {
  32 +// //@selector(dataTaskWithRequest:completionHandler:),
  33 +// //@selector(downloadTaskWithRequest:completionHandler:),
  34 +// };
  35 +//
  36 +// for (NSUInteger index = 0; index < sizeof(selectors) / sizeof(SEL); ++index) {
  37 +// SEL originalSelector = selectors[index];
  38 +// SEL swizzledSelector = NSSelectorFromString([@"yher_" stringByAppendingString:NSStringFromSelector(originalSelector)]);
  39 +// NSError *error = NULL;
  40 +// [[self class] yh_swizzleMethod:originalSelector
  41 +// withMethod:swizzledSelector
  42 +// error:&error];
  43 +// if (error) {
  44 +// YHLog(@"Failed to swizzle: on UIControl. Details: %@", error);
  45 +// error = NULL;
  46 +// }
  47 +// }
  48 +//
  49 +// } @catch (NSException *exception) {
  50 +// YHLog(@"%@ error: %@", self, exception);
  51 +// }
  52 +// });
53 } 53 }
54 54
55 55
@@ -162,9 +162,10 @@ static inline BOOL yher_addMethod(Class class, SEL selector, Method method) { @@ -162,9 +162,10 @@ static inline BOOL yher_addMethod(Class class, SEL selector, Method method) {
162 - (void)yher_resume 162 - (void)yher_resume
163 { 163 {
164 @try { 164 @try {
165 - if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].isHttpPerformanceTrackEnable) {  
166 - NSURLSessionTask *task = (NSURLSessionTask*)self;  
167 - [[YH_EventCollector sharedInstance] timeEventStartWithRequestUrl:[task.currentRequest.URL absoluteString]]; 165 + NSURLSessionTask *task = (NSURLSessionTask*)self;
  166 + NSString *hostInHTTPField = [task.originalRequest.allHTTPHeaderFields objectForKey:@"Host"];
  167 + if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].isHttpPerformanceTrackEnable && ([[task.originalRequest.URL host] isEqualToString:YHEventReportHttpHost] || [hostInHTTPField isEqualToString:YHEventReportHttpHost])) {
  168 + [[YH_EventCollector sharedInstance] timeEventStartWithRequestUrl:[task.originalRequest.URL absoluteString]];
168 } 169 }
169 } @catch (NSException *exception) { 170 } @catch (NSException *exception) {
170 YHLog(@"%@ error: %@", self, exception); 171 YHLog(@"%@ error: %@", self, exception);
@@ -173,3 +174,4 @@ static inline BOOL yher_addMethod(Class class, SEL selector, Method method) { @@ -173,3 +174,4 @@ static inline BOOL yher_addMethod(Class class, SEL selector, Method method) {
173 } 174 }
174 175
175 @end 176 @end
  177 +