diff --git a/Foundation/URLSession/URLSessionTask.swift b/Foundation/URLSession/URLSessionTask.swift index f6f5fc128b..494c219b5b 100644 --- a/Foundation/URLSession/URLSessionTask.swift +++ b/Foundation/URLSession/URLSessionTask.swift @@ -574,11 +574,8 @@ extension _ProtocolClient : URLProtocolClient { sender: `protocol` as! _HTTPURLProtocol) task.previousFailureCount += 1 urlProtocol(`protocol`, didReceive: authenticationChallenge) - } else { - let urlError = URLError(_nsError: NSError(domain: NSURLErrorDomain, code: NSURLErrorUserAuthenticationRequired, userInfo: nil)) - urlProtocol(`protocol`, didFailWithError: urlError) + return } - return } switch session.behaviour(for: task) { case .taskDelegate(let delegate): diff --git a/TestFoundation/TestURLSession.swift b/TestFoundation/TestURLSession.swift index 48f8265fdb..4e5943926d 100644 --- a/TestFoundation/TestURLSession.swift +++ b/TestFoundation/TestURLSession.swift @@ -766,9 +766,10 @@ class TestURLSession : LoopbackServerTest { let expect = expectation(description: "GET \(urlString): with a completion handler") var expectedResult = "unknown" let session = URLSession(configuration: URLSessionConfiguration.default) - let task = session.dataTask(with: url) { _, _, error in + let task = session.dataTask(with: url) { _, response, error in defer { expect.fulfill() } - XCTAssertNotNil(error) + XCTAssertNotNil(response) + XCTAssertNil(error) } task.resume() waitForExpectations(timeout: 12, handler: nil)