Skip to content

Commit d557d9e

Browse files
authored
Merge pull request #1174 from KyeMaloy97/URLStubbing
2 parents d78824b + aa77c95 commit d557d9e

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

Foundation/URLSession/URLSession.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,13 @@
171171
import CoreFoundation
172172
import Dispatch
173173

174+
extension URLSession {
175+
public enum DelayedRequestDisposition {
176+
case cancel
177+
case continueLoading
178+
case useNewRequest
179+
}
180+
}
174181

175182
fileprivate var sessionCounter = Int32(0)
176183
fileprivate func nextSessionIdentifier() -> Int32 {

Foundation/URLSession/URLSessionDelegate.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ public protocol URLSessionTaskDelegate : URLSessionDelegate {
119119
* nil, which implies that no error occurred and this task is complete.
120120
*/
121121
func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?)
122+
123+
func urlSession(_ session: URLSession, task: URLSessionTask, willBeginDelayedRequest request: URLRequest, completionHandler: @escaping (URLSession.DelayedRequestDisposition, URLRequest?) -> Void)
122124
}
123125

124126
extension URLSessionTaskDelegate {
@@ -137,6 +139,8 @@ extension URLSessionTaskDelegate {
137139
public func urlSession(_ session: URLSession, task: URLSessionTask, didSendBodyData bytesSent: Int64, totalBytesSent: Int64, totalBytesExpectedToSend: Int64) { }
138140

139141
public func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) { }
142+
143+
public func urlSession(_ session: URLSession, task: URLSessionTask, willBeginDelayedRequest request: URLRequest, completionHandler: @escaping (URLSession.DelayedRequestDisposition, URLRequest?) -> Void) { }
140144
}
141145

142146
/*
@@ -194,6 +198,7 @@ public protocol URLSessionDataDelegate : URLSessionTaskDelegate {
194198
* message to receive the resource data.
195199
*/
196200
func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, willCacheResponse proposedResponse: CachedURLResponse, completionHandler: @escaping (CachedURLResponse?) -> Void)
201+
197202
}
198203

199204
extension URLSessionDataDelegate {

0 commit comments

Comments
 (0)