Skip to content

Commit 0f28ef1

Browse files
authored
Merge pull request swiftlang#2255 from finestructure/swift-5.0-branch
Don't fail a URLSessionTask on a 401 response
2 parents 225bc35 + e7a517e commit 0f28ef1

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
@@ -574,11 +574,8 @@ extension _ProtocolClient : URLProtocolClient {
574574
sender: `protocol` as! _HTTPURLProtocol)
575575
task.previousFailureCount += 1
576576
urlProtocol(`protocol`, didReceive: authenticationChallenge)
577-
} else {
578-
let urlError = URLError(_nsError: NSError(domain: NSURLErrorDomain, code: NSURLErrorUserAuthenticationRequired, userInfo: nil))
579-
urlProtocol(`protocol`, didFailWithError: urlError)
577+
return
580578
}
581-
return
582579
}
583580
switch session.behaviour(for: task) {
584581
case .taskDelegate(let delegate):

TestFoundation/TestURLSession.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,9 +766,10 @@ class TestURLSession : LoopbackServerTest {
766766
let expect = expectation(description: "GET \(urlString): with a completion handler")
767767
var expectedResult = "unknown"
768768
let session = URLSession(configuration: URLSessionConfiguration.default)
769-
let task = session.dataTask(with: url) { _, _, error in
769+
let task = session.dataTask(with: url) { _, response, error in
770770
defer { expect.fulfill() }
771-
XCTAssertNotNil(error)
771+
XCTAssertNotNil(response)
772+
XCTAssertNil(error)
772773
}
773774
task.resume()
774775
waitForExpectations(timeout: 12, handler: nil)

0 commit comments

Comments
 (0)