Skip to content

Commit

Permalink
Verify that the parameter to +[NSURLComponents initWithURL:resolvingA…
Browse files Browse the repository at this point in the history
…gainstBaseURL:] is not nil
  • Loading branch information
kstenerud committed Nov 18, 2021
1 parent 2f8866f commit 740c26b
Showing 1 changed file with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ + (nonnull NSString *)URLStringWithoutQueryForComponents:(nonnull NSURLComponent
- (void)URLSession:(__unused NSURLSession *)session task:(NSURLSessionTask *)task didFinishCollectingMetrics:(NSURLSessionTaskMetrics *)metrics
API_AVAILABLE(macosx(10.12), ios(10.0), watchos(3.0), tvos(10.0)) {
if (g_sink != nil) {
// Note: Cannot use metrics transaction request because it might have a 0 length HTTP body.
NSURLRequest *req = task.originalRequest;
NSURLComponents *urlComponents = [NSURLComponents componentsWithURL:req.URL resolvingAgainstBaseURL:YES];
// Note: Cannot use metrics transaction response because it will be nil if a custom NSURLProtocol is present.
// Note: If there was an error, task.response will be nil, and the following values will be set accordingly.
NSHTTPURLResponse *httpResp = [task.response isKindOfClass:NSHTTPURLResponse.class] ? (NSHTTPURLResponse *)task.response : nil;
Expand All @@ -97,9 +94,20 @@ - (void)URLSession:(__unused NSURLSession *)session task:(NSURLSessionTask *)tas

NSMutableDictionary *metadata = [NSMutableDictionary dictionary];
metadata[@"duration"] = @((unsigned)(metrics.taskInterval.duration * 1000));
metadata[@"method"] = req.HTTPMethod;
metadata[@"url"] = [BSGURLSessionTracingDelegate URLStringWithoutQueryForComponents:urlComponents];
metadata[@"urlParams"] = [BSGURLSessionTracingDelegate urlParamsForQueryItems:urlComponents.queryItems];

NSURLRequest *req = task.originalRequest;
if (req == nil) {
req = task.currentRequest;
}
if (req) {
metadata[@"method"] = req.HTTPMethod;
if (req.URL) {
NSURLComponents *urlComponents = [NSURLComponents componentsWithURL:req.URL resolvingAgainstBaseURL:YES];
metadata[@"url"] = [BSGURLSessionTracingDelegate URLStringWithoutQueryForComponents:urlComponents];
metadata[@"urlParams"] = [BSGURLSessionTracingDelegate urlParamsForQueryItems:urlComponents.queryItems];
}
}

if (task.countOfBytesSent) {
metadata[@"requestContentLength"] = @(task.countOfBytesSent);
} else if (req.HTTPBody) {
Expand Down

0 comments on commit 740c26b

Please sign in to comment.