From 4bf3628bfc2615fdd8cca4b6bbc98de37696061d Mon Sep 17 00:00:00 2001 From: Ignacio Bonafonte Date: Thu, 19 Nov 2020 18:53:14 +0100 Subject: [PATCH] CIAPP-570 - Adjust network instrumentation for dd-sdk usage Don't convert requests made with URL to URLRequest if we are not injecting headers, since it is not needed --- .../NetworkInstrumentation/DDNetworkInstrumentation.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sources/DatadogSDKTesting/NetworkInstrumentation/DDNetworkInstrumentation.swift b/Sources/DatadogSDKTesting/NetworkInstrumentation/DDNetworkInstrumentation.swift index cab8fc34..60ee710f 100644 --- a/Sources/DatadogSDKTesting/NetworkInstrumentation/DDNetworkInstrumentation.swift +++ b/Sources/DatadogSDKTesting/NetworkInstrumentation/DDNetworkInstrumentation.swift @@ -103,7 +103,8 @@ class DDNetworkInstrumentation { let sessionTaskId = UUID().uuidString let block: @convention(block) (URLSession, AnyObject) -> URLSessionTask = { session, argument in - if let url = argument as? URL { + if let url = argument as? URL, + self.injectHeaders == true { let request = URLRequest(url: url) if selector == #selector(URLSession.dataTask(with:) as (URLSession) -> (URL) -> URLSessionDataTask) { return session.dataTask(with: request) @@ -179,7 +180,8 @@ class DDNetworkInstrumentation { let sessionTaskId = UUID().uuidString let block: @convention(block) (URLSession, AnyObject, @escaping (Any?, URLResponse?, Error?) -> Void) -> URLSessionTask = { session, argument, completion in - if let url = argument as? URL { + if let url = argument as? URL, + self.injectHeaders == true { let request = URLRequest(url: url) if selector == #selector(URLSession.dataTask(with:completionHandler:) as (URLSession) -> (URL, @escaping (Data?, URLResponse?, Error?) -> Void) -> URLSessionDataTask) {