Skip to content

Commit 263ce3c

Browse files
authored
Merge pull request #2214 from pushkarnk/basic-auth-regression
[SR-10602]Don't fail a URLSessionTask on a 401 response
2 parents f9f3d46 + 3a7d267 commit 263ce3c

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

Foundation/URLSession/URLSessionTask.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -579,11 +579,8 @@ extension _ProtocolClient : URLProtocolClient {
579579
sender: `protocol` as! _HTTPURLProtocol)
580580
task.previousFailureCount += 1
581581
urlProtocol(`protocol`, didReceive: authenticationChallenge)
582-
} else {
583-
let urlError = URLError(_nsError: NSError(domain: NSURLErrorDomain, code: NSURLErrorUserAuthenticationRequired, userInfo: nil))
584-
urlProtocol(`protocol`, didFailWithError: urlError)
582+
return
585583
}
586-
return
587584
}
588585
switch session.behaviour(for: task) {
589586
case .taskDelegate(let delegate):

TestFoundation/TestURLSession.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -795,9 +795,10 @@ class TestURLSession : LoopbackServerTest {
795795
let expect = expectation(description: "GET \(urlString): with a completion handler")
796796
var expectedResult = "unknown"
797797
let session = URLSession(configuration: URLSessionConfiguration.default)
798-
let task = session.dataTask(with: url) { _, _, error in
798+
let task = session.dataTask(with: url) { _, response, error in
799799
defer { expect.fulfill() }
800-
XCTAssertNotNil(error)
800+
XCTAssertNotNil(response)
801+
XCTAssertNil(error)
801802
}
802803
task.resume()
803804
waitForExpectations(timeout: 12, handler: nil)

0 commit comments

Comments
 (0)