...
|
...
|
@@ -131,31 +131,45 @@ |
|
|
|
|
|
- (void)yher_start
|
|
|
{
|
|
|
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].httpPerformanceTrackEnable) {
|
|
|
[[YH_EventCollector sharedInstance] timeEventStartWithRequestUrl:[self.currentRequest.URL absoluteString]];
|
|
|
@try {
|
|
|
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].httpPerformanceTrackEnable) {
|
|
|
[[YH_EventCollector sharedInstance] timeEventStartWithRequestUrl:[self.currentRequest.URL absoluteString]];
|
|
|
}
|
|
|
} @catch (NSException *exception) {
|
|
|
YHLog(@"%@ error: %@", self, exception);
|
|
|
}
|
|
|
|
|
|
[self yher_start];
|
|
|
}
|
|
|
|
|
|
+ (nullable NSData *)yher_sendSynchronousRequest:(NSURLRequest *)request returningResponse:(NSURLResponse * _Nullable * _Nullable)response error:(NSError **)error
|
|
|
{
|
|
|
NSString *hostInHTTPField = [request.allHTTPHeaderFields objectForKey:@"Host"];
|
|
|
|
|
|
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].httpPerformanceTrackEnable && ([[request.URL host] isEqualToString:YHEventReportHttpHost] || [hostInHTTPField isEqualToString:YHEventReportHttpHost])) {
|
|
|
[[YH_EventCollector sharedInstance] timeEventStartWithRequestUrl:[request.URL absoluteString]];
|
|
|
|
|
|
@try {
|
|
|
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].httpPerformanceTrackEnable && ([[request.URL host] isEqualToString:YHEventReportHttpHost] || [hostInHTTPField isEqualToString:YHEventReportHttpHost])) {
|
|
|
[[YH_EventCollector sharedInstance] timeEventStartWithRequestUrl:[request.URL absoluteString]];
|
|
|
}
|
|
|
} @catch (NSException *exception) {
|
|
|
YHLog(@"%@ error: %@", self, exception);
|
|
|
}
|
|
|
|
|
|
NSData *data = [self yher_sendSynchronousRequest:request returningResponse:response error:error];
|
|
|
|
|
|
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].httpPerformanceTrackEnable && !error && ([[request.URL host] isEqualToString:YHEventReportHttpHost] || [hostInHTTPField isEqualToString:YHEventReportHttpHost])) {
|
|
|
NSURLResponse *res = *response;
|
|
|
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)res;
|
|
|
NSDictionary *httpResponseHeaderFields = [httpResponse allHeaderFields];
|
|
|
NSString *contentLength = [NSString stringWithFormat:@"%lld",[[httpResponseHeaderFields objectForKey:@"Content-Length"] longLongValue]];
|
|
|
NSString *statusCode = [NSString stringWithFormat:@"%ld",(long)httpResponse.statusCode];
|
|
|
|
|
|
[[YH_EventCollector sharedInstance] timeEventEndWithRequestUrl:[request.URL absoluteString] HTTPMethod:request.HTTPMethod statusCode:statusCode contentLength:contentLength];
|
|
|
@try {
|
|
|
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].httpPerformanceTrackEnable && !error && ([[request.URL host] isEqualToString:YHEventReportHttpHost] || [hostInHTTPField isEqualToString:YHEventReportHttpHost])) {
|
|
|
NSURLResponse *res = *response;
|
|
|
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)res;
|
|
|
NSDictionary *httpResponseHeaderFields = [httpResponse allHeaderFields];
|
|
|
NSString *contentLength = [NSString stringWithFormat:@"%lld",[[httpResponseHeaderFields objectForKey:@"Content-Length"] longLongValue]];
|
|
|
NSString *statusCode = [NSString stringWithFormat:@"%ld",(long)httpResponse.statusCode];
|
|
|
|
|
|
[[YH_EventCollector sharedInstance] timeEventEndWithRequestUrl:[request.URL absoluteString] HTTPMethod:request.HTTPMethod statusCode:statusCode contentLength:contentLength];
|
|
|
}
|
|
|
} @catch (NSException *exception) {
|
|
|
YHLog(@"%@ error: %@", self, exception);
|
|
|
}
|
|
|
|
|
|
return data;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -174,15 +188,20 @@ |
|
|
if (handler) {
|
|
|
handler(response,data,connectionError);
|
|
|
}
|
|
|
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].httpPerformanceTrackEnable && !connectionError && ([[request.URL host] isEqualToString:YHEventReportHttpHost] || [hostInHTTPField isEqualToString:YHEventReportHttpHost])) {
|
|
|
|
|
|
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response;
|
|
|
NSDictionary *httpResponseHeaderFields = [httpResponse allHeaderFields];
|
|
|
NSString *contentLength = [NSString stringWithFormat:@"%lld",[[httpResponseHeaderFields objectForKey:@"Content-Length"] longLongValue]];
|
|
|
NSString *statusCode = [NSString stringWithFormat:@"%ld",(long)httpResponse.statusCode];
|
|
|
|
|
|
[[YH_EventCollector sharedInstance] timeEventEndWithRequestUrl:[request.URL absoluteString] HTTPMethod:request.HTTPMethod statusCode:statusCode contentLength:contentLength];
|
|
|
|
|
|
|
|
|
@try {
|
|
|
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].httpPerformanceTrackEnable && !connectionError && ([[request.URL host] isEqualToString:YHEventReportHttpHost] || [hostInHTTPField isEqualToString:YHEventReportHttpHost])) {
|
|
|
|
|
|
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response;
|
|
|
NSDictionary *httpResponseHeaderFields = [httpResponse allHeaderFields];
|
|
|
NSString *contentLength = [NSString stringWithFormat:@"%lld",[[httpResponseHeaderFields objectForKey:@"Content-Length"] longLongValue]];
|
|
|
NSString *statusCode = [NSString stringWithFormat:@"%ld",(long)httpResponse.statusCode];
|
|
|
|
|
|
[[YH_EventCollector sharedInstance] timeEventEndWithRequestUrl:[request.URL absoluteString] HTTPMethod:request.HTTPMethod statusCode:statusCode contentLength:contentLength];
|
|
|
|
|
|
}
|
|
|
} @catch (NSException *exception) {
|
|
|
YHLog(@"%@ error: %@", self, exception);
|
|
|
}
|
|
|
}];
|
|
|
}
|
...
|
...
|
@@ -206,14 +225,19 @@ |
|
|
if (self.my_delegate && [self.my_delegate respondsToSelector:@selector(connectionDidFinishLoading:)]) {
|
|
|
[self.my_delegate connectionDidFinishLoading:connection];
|
|
|
}
|
|
|
NSString *hostInHTTPField = [connection.currentRequest.allHTTPHeaderFields objectForKey:@"Host"];
|
|
|
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].httpPerformanceTrackEnable && ([[connection.currentRequest.URL host] isEqualToString:YHEventReportHttpHost] || [hostInHTTPField isEqualToString:YHEventReportHttpHost])) {
|
|
|
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)connection.my_response;
|
|
|
NSDictionary *httpResponseHeaderFields = [httpResponse allHeaderFields];
|
|
|
NSString *contentLength = [NSString stringWithFormat:@"%lld",[[httpResponseHeaderFields objectForKey:@"Content-Length"] longLongValue]];
|
|
|
NSString *statusCode = [NSString stringWithFormat:@"%ld",(long)httpResponse.statusCode];
|
|
|
|
|
|
[[YH_EventCollector sharedInstance] timeEventEndWithRequestUrl:[connection.currentRequest.URL absoluteString] HTTPMethod:connection.currentRequest.HTTPMethod statusCode:statusCode contentLength:contentLength];
|
|
|
|
|
|
@try {
|
|
|
NSString *hostInHTTPField = [connection.currentRequest.allHTTPHeaderFields objectForKey:@"Host"];
|
|
|
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].httpPerformanceTrackEnable && ([[connection.currentRequest.URL host] isEqualToString:YHEventReportHttpHost] || [hostInHTTPField isEqualToString:YHEventReportHttpHost])) {
|
|
|
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)connection.my_response;
|
|
|
NSDictionary *httpResponseHeaderFields = [httpResponse allHeaderFields];
|
|
|
NSString *contentLength = [NSString stringWithFormat:@"%lld",[[httpResponseHeaderFields objectForKey:@"Content-Length"] longLongValue]];
|
|
|
NSString *statusCode = [NSString stringWithFormat:@"%ld",(long)httpResponse.statusCode];
|
|
|
|
|
|
[[YH_EventCollector sharedInstance] timeEventEndWithRequestUrl:[connection.currentRequest.URL absoluteString] HTTPMethod:connection.currentRequest.HTTPMethod statusCode:statusCode contentLength:contentLength];
|
|
|
}
|
|
|
} @catch (NSException *exception) {
|
|
|
YHLog(@"%@ error: %@", self, exception);
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
|