pod-builder 1.9.2 → 2.0.0.beta.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +9 -0
  3. data/Example/Frameworks/.gitignore +6 -0
  4. data/Example/Frameworks/.pod_builder/pod_builder +0 -0
  5. data/Example/Frameworks/PodBuilder.json +10 -4
  6. data/Example/Frameworks/Podfile +23 -0
  7. data/Example/Frameworks/Podfile.restore +40 -0
  8. data/Example/PodBuilderExample.xcodeproj/project.pbxproj +3 -8
  9. data/Example/{PodBuilderExample.xcodeproj/xcuserdata/tomas.xcuserdatad/xcschemes/xcschememanagement.plist → PodBuilderExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist} +2 -8
  10. data/Example/PodBuilderExample/AppDelegate.swift +4 -0
  11. data/Example/Podfile +44 -1
  12. data/Example/Podfile.lock +426 -7
  13. data/Example/Pods-acknowledgements.md +210 -0
  14. data/Example/Pods-acknowledgements.plist +206 -0
  15. data/README.md +38 -1
  16. data/exe/pod_builder +14 -14
  17. data/lib/pod_builder/analyze.rb +32 -7
  18. data/lib/pod_builder/analyzer.rb +16 -0
  19. data/lib/pod_builder/command/build.rb +110 -96
  20. data/lib/pod_builder/command/clean.rb +9 -11
  21. data/lib/pod_builder/command/clear_lldbinit.rb +1 -1
  22. data/lib/pod_builder/command/deintegrate.rb +2 -1
  23. data/lib/pod_builder/command/generate_lfs.rb +2 -2
  24. data/lib/pod_builder/command/install_sources.rb +1 -1
  25. data/lib/pod_builder/command/switch.rb +99 -99
  26. data/lib/pod_builder/command/sync_podfile.rb +2 -1
  27. data/lib/pod_builder/command/update.rb +1 -1
  28. data/lib/pod_builder/command/update_lldbinit.rb +2 -2
  29. data/lib/pod_builder/configuration.rb +62 -7
  30. data/lib/pod_builder/core.rb +60 -5
  31. data/lib/pod_builder/info.rb +24 -90
  32. data/lib/pod_builder/install.rb +149 -83
  33. data/lib/pod_builder/podfile.rb +87 -14
  34. data/lib/pod_builder/podfile/post_actions.rb +0 -1
  35. data/lib/pod_builder/podfile_item.rb +152 -74
  36. data/lib/pod_builder/podspec.rb +125 -133
  37. data/lib/pod_builder/rome/post_install.rb +248 -0
  38. data/lib/pod_builder/rome/pre_install.rb +6 -0
  39. data/lib/pod_builder/templates/build_podfile.template +1 -1
  40. data/lib/pod_builder/version.rb +1 -1
  41. data/pod-builder.gemspec +4 -4
  42. metadata +32 -64
  43. data/Example/Pods/Alamofire/LICENSE +0 -19
  44. data/Example/Pods/Alamofire/README.md +0 -242
  45. data/Example/Pods/Alamofire/Source/AFError.swift +0 -460
  46. data/Example/Pods/Alamofire/Source/Alamofire.swift +0 -465
  47. data/Example/Pods/Alamofire/Source/DispatchQueue+Alamofire.swift +0 -37
  48. data/Example/Pods/Alamofire/Source/MultipartFormData.swift +0 -580
  49. data/Example/Pods/Alamofire/Source/NetworkReachabilityManager.swift +0 -233
  50. data/Example/Pods/Alamofire/Source/Notifications.swift +0 -55
  51. data/Example/Pods/Alamofire/Source/ParameterEncoding.swift +0 -483
  52. data/Example/Pods/Alamofire/Source/Request.swift +0 -654
  53. data/Example/Pods/Alamofire/Source/Response.swift +0 -567
  54. data/Example/Pods/Alamofire/Source/ResponseSerialization.swift +0 -715
  55. data/Example/Pods/Alamofire/Source/Result.swift +0 -300
  56. data/Example/Pods/Alamofire/Source/ServerTrustPolicy.swift +0 -307
  57. data/Example/Pods/Alamofire/Source/SessionDelegate.swift +0 -725
  58. data/Example/Pods/Alamofire/Source/SessionManager.swift +0 -896
  59. data/Example/Pods/Alamofire/Source/TaskDelegate.swift +0 -466
  60. data/Example/Pods/Alamofire/Source/Timeline.swift +0 -136
  61. data/Example/Pods/Alamofire/Source/Validation.swift +0 -315
  62. data/Example/Pods/Manifest.lock +0 -16
  63. data/Example/Pods/Pods.xcodeproj/project.pbxproj +0 -673
  64. data/Example/Pods/Pods.xcodeproj/xcuserdata/tomas.xcuserdatad/xcschemes/Alamofire.xcscheme +0 -60
  65. data/Example/Pods/Pods.xcodeproj/xcuserdata/tomas.xcuserdatad/xcschemes/Pods-PodBuilderExample.xcscheme +0 -60
  66. data/Example/Pods/Pods.xcodeproj/xcuserdata/tomas.xcuserdatad/xcschemes/xcschememanagement.plist +0 -21
  67. data/Example/Pods/Target Support Files/Alamofire/Alamofire-dummy.m +0 -5
  68. data/Example/Pods/Target Support Files/Alamofire/Alamofire-prefix.pch +0 -12
  69. data/Example/Pods/Target Support Files/Alamofire/Alamofire-umbrella.h +0 -16
  70. data/Example/Pods/Target Support Files/Alamofire/Alamofire.modulemap +0 -6
  71. data/Example/Pods/Target Support Files/Alamofire/Alamofire.xcconfig +0 -9
  72. data/Example/Pods/Target Support Files/Alamofire/Info.plist +0 -26
  73. data/Example/Pods/Target Support Files/Pods-PodBuilderExample/Info.plist +0 -26
  74. data/Example/Pods/Target Support Files/Pods-PodBuilderExample/Pods-PodBuilderExample-acknowledgements.markdown +0 -26
  75. data/Example/Pods/Target Support Files/Pods-PodBuilderExample/Pods-PodBuilderExample-acknowledgements.plist +0 -58
  76. data/Example/Pods/Target Support Files/Pods-PodBuilderExample/Pods-PodBuilderExample-dummy.m +0 -5
  77. data/Example/Pods/Target Support Files/Pods-PodBuilderExample/Pods-PodBuilderExample-frameworks.sh +0 -153
  78. data/Example/Pods/Target Support Files/Pods-PodBuilderExample/Pods-PodBuilderExample-resources.sh +0 -118
  79. data/Example/Pods/Target Support Files/Pods-PodBuilderExample/Pods-PodBuilderExample-umbrella.h +0 -16
  80. data/Example/Pods/Target Support Files/Pods-PodBuilderExample/Pods-PodBuilderExample.debug.xcconfig +0 -11
  81. data/Example/Pods/Target Support Files/Pods-PodBuilderExample/Pods-PodBuilderExample.modulemap +0 -6
  82. data/Example/Pods/Target Support Files/Pods-PodBuilderExample/Pods-PodBuilderExample.release.xcconfig +0 -11
  83. data/lib/pod_builder/cocoapods/specification.rb +0 -27
@@ -1,725 +0,0 @@
1
- //
2
- // SessionDelegate.swift
3
- //
4
- // Copyright (c) 2014-2018 Alamofire Software Foundation (http://alamofire.org/)
5
- //
6
- // Permission is hereby granted, free of charge, to any person obtaining a copy
7
- // of this software and associated documentation files (the "Software"), to deal
8
- // in the Software without restriction, including without limitation the rights
9
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- // copies of the Software, and to permit persons to whom the Software is
11
- // furnished to do so, subject to the following conditions:
12
- //
13
- // The above copyright notice and this permission notice shall be included in
14
- // all copies or substantial portions of the Software.
15
- //
16
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
- // THE SOFTWARE.
23
- //
24
-
25
- import Foundation
26
-
27
- /// Responsible for handling all delegate callbacks for the underlying session.
28
- open class SessionDelegate: NSObject {
29
-
30
- // MARK: URLSessionDelegate Overrides
31
-
32
- /// Overrides default behavior for URLSessionDelegate method `urlSession(_:didBecomeInvalidWithError:)`.
33
- open var sessionDidBecomeInvalidWithError: ((URLSession, Error?) -> Void)?
34
-
35
- /// Overrides default behavior for URLSessionDelegate method `urlSession(_:didReceive:completionHandler:)`.
36
- open var sessionDidReceiveChallenge: ((URLSession, URLAuthenticationChallenge) -> (URLSession.AuthChallengeDisposition, URLCredential?))?
37
-
38
- /// Overrides all behavior for URLSessionDelegate method `urlSession(_:didReceive:completionHandler:)` and requires the caller to call the `completionHandler`.
39
- open var sessionDidReceiveChallengeWithCompletion: ((URLSession, URLAuthenticationChallenge, @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) -> Void)?
40
-
41
- /// Overrides default behavior for URLSessionDelegate method `urlSessionDidFinishEvents(forBackgroundURLSession:)`.
42
- open var sessionDidFinishEventsForBackgroundURLSession: ((URLSession) -> Void)?
43
-
44
- // MARK: URLSessionTaskDelegate Overrides
45
-
46
- /// Overrides default behavior for URLSessionTaskDelegate method `urlSession(_:task:willPerformHTTPRedirection:newRequest:completionHandler:)`.
47
- open var taskWillPerformHTTPRedirection: ((URLSession, URLSessionTask, HTTPURLResponse, URLRequest) -> URLRequest?)?
48
-
49
- /// Overrides all behavior for URLSessionTaskDelegate method `urlSession(_:task:willPerformHTTPRedirection:newRequest:completionHandler:)` and
50
- /// requires the caller to call the `completionHandler`.
51
- open var taskWillPerformHTTPRedirectionWithCompletion: ((URLSession, URLSessionTask, HTTPURLResponse, URLRequest, @escaping (URLRequest?) -> Void) -> Void)?
52
-
53
- /// Overrides default behavior for URLSessionTaskDelegate method `urlSession(_:task:didReceive:completionHandler:)`.
54
- open var taskDidReceiveChallenge: ((URLSession, URLSessionTask, URLAuthenticationChallenge) -> (URLSession.AuthChallengeDisposition, URLCredential?))?
55
-
56
- /// Overrides all behavior for URLSessionTaskDelegate method `urlSession(_:task:didReceive:completionHandler:)` and
57
- /// requires the caller to call the `completionHandler`.
58
- open var taskDidReceiveChallengeWithCompletion: ((URLSession, URLSessionTask, URLAuthenticationChallenge, @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) -> Void)?
59
-
60
- /// Overrides default behavior for URLSessionTaskDelegate method `urlSession(_:task:needNewBodyStream:)`.
61
- open var taskNeedNewBodyStream: ((URLSession, URLSessionTask) -> InputStream?)?
62
-
63
- /// Overrides all behavior for URLSessionTaskDelegate method `urlSession(_:task:needNewBodyStream:)` and
64
- /// requires the caller to call the `completionHandler`.
65
- open var taskNeedNewBodyStreamWithCompletion: ((URLSession, URLSessionTask, @escaping (InputStream?) -> Void) -> Void)?
66
-
67
- /// Overrides default behavior for URLSessionTaskDelegate method `urlSession(_:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:)`.
68
- open var taskDidSendBodyData: ((URLSession, URLSessionTask, Int64, Int64, Int64) -> Void)?
69
-
70
- /// Overrides default behavior for URLSessionTaskDelegate method `urlSession(_:task:didCompleteWithError:)`.
71
- open var taskDidComplete: ((URLSession, URLSessionTask, Error?) -> Void)?
72
-
73
- // MARK: URLSessionDataDelegate Overrides
74
-
75
- /// Overrides default behavior for URLSessionDataDelegate method `urlSession(_:dataTask:didReceive:completionHandler:)`.
76
- open var dataTaskDidReceiveResponse: ((URLSession, URLSessionDataTask, URLResponse) -> URLSession.ResponseDisposition)?
77
-
78
- /// Overrides all behavior for URLSessionDataDelegate method `urlSession(_:dataTask:didReceive:completionHandler:)` and
79
- /// requires caller to call the `completionHandler`.
80
- open var dataTaskDidReceiveResponseWithCompletion: ((URLSession, URLSessionDataTask, URLResponse, @escaping (URLSession.ResponseDisposition) -> Void) -> Void)?
81
-
82
- /// Overrides default behavior for URLSessionDataDelegate method `urlSession(_:dataTask:didBecome:)`.
83
- open var dataTaskDidBecomeDownloadTask: ((URLSession, URLSessionDataTask, URLSessionDownloadTask) -> Void)?
84
-
85
- /// Overrides default behavior for URLSessionDataDelegate method `urlSession(_:dataTask:didReceive:)`.
86
- open var dataTaskDidReceiveData: ((URLSession, URLSessionDataTask, Data) -> Void)?
87
-
88
- /// Overrides default behavior for URLSessionDataDelegate method `urlSession(_:dataTask:willCacheResponse:completionHandler:)`.
89
- open var dataTaskWillCacheResponse: ((URLSession, URLSessionDataTask, CachedURLResponse) -> CachedURLResponse?)?
90
-
91
- /// Overrides all behavior for URLSessionDataDelegate method `urlSession(_:dataTask:willCacheResponse:completionHandler:)` and
92
- /// requires caller to call the `completionHandler`.
93
- open var dataTaskWillCacheResponseWithCompletion: ((URLSession, URLSessionDataTask, CachedURLResponse, @escaping (CachedURLResponse?) -> Void) -> Void)?
94
-
95
- // MARK: URLSessionDownloadDelegate Overrides
96
-
97
- /// Overrides default behavior for URLSessionDownloadDelegate method `urlSession(_:downloadTask:didFinishDownloadingTo:)`.
98
- open var downloadTaskDidFinishDownloadingToURL: ((URLSession, URLSessionDownloadTask, URL) -> Void)?
99
-
100
- /// Overrides default behavior for URLSessionDownloadDelegate method `urlSession(_:downloadTask:didWriteData:totalBytesWritten:totalBytesExpectedToWrite:)`.
101
- open var downloadTaskDidWriteData: ((URLSession, URLSessionDownloadTask, Int64, Int64, Int64) -> Void)?
102
-
103
- /// Overrides default behavior for URLSessionDownloadDelegate method `urlSession(_:downloadTask:didResumeAtOffset:expectedTotalBytes:)`.
104
- open var downloadTaskDidResumeAtOffset: ((URLSession, URLSessionDownloadTask, Int64, Int64) -> Void)?
105
-
106
- // MARK: URLSessionStreamDelegate Overrides
107
-
108
- #if !os(watchOS)
109
-
110
- /// Overrides default behavior for URLSessionStreamDelegate method `urlSession(_:readClosedFor:)`.
111
- @available(iOS 9.0, macOS 10.11, tvOS 9.0, *)
112
- open var streamTaskReadClosed: ((URLSession, URLSessionStreamTask) -> Void)? {
113
- get {
114
- return _streamTaskReadClosed as? (URLSession, URLSessionStreamTask) -> Void
115
- }
116
- set {
117
- _streamTaskReadClosed = newValue
118
- }
119
- }
120
-
121
- /// Overrides default behavior for URLSessionStreamDelegate method `urlSession(_:writeClosedFor:)`.
122
- @available(iOS 9.0, macOS 10.11, tvOS 9.0, *)
123
- open var streamTaskWriteClosed: ((URLSession, URLSessionStreamTask) -> Void)? {
124
- get {
125
- return _streamTaskWriteClosed as? (URLSession, URLSessionStreamTask) -> Void
126
- }
127
- set {
128
- _streamTaskWriteClosed = newValue
129
- }
130
- }
131
-
132
- /// Overrides default behavior for URLSessionStreamDelegate method `urlSession(_:betterRouteDiscoveredFor:)`.
133
- @available(iOS 9.0, macOS 10.11, tvOS 9.0, *)
134
- open var streamTaskBetterRouteDiscovered: ((URLSession, URLSessionStreamTask) -> Void)? {
135
- get {
136
- return _streamTaskBetterRouteDiscovered as? (URLSession, URLSessionStreamTask) -> Void
137
- }
138
- set {
139
- _streamTaskBetterRouteDiscovered = newValue
140
- }
141
- }
142
-
143
- /// Overrides default behavior for URLSessionStreamDelegate method `urlSession(_:streamTask:didBecome:outputStream:)`.
144
- @available(iOS 9.0, macOS 10.11, tvOS 9.0, *)
145
- open var streamTaskDidBecomeInputAndOutputStreams: ((URLSession, URLSessionStreamTask, InputStream, OutputStream) -> Void)? {
146
- get {
147
- return _streamTaskDidBecomeInputStream as? (URLSession, URLSessionStreamTask, InputStream, OutputStream) -> Void
148
- }
149
- set {
150
- _streamTaskDidBecomeInputStream = newValue
151
- }
152
- }
153
-
154
- var _streamTaskReadClosed: Any?
155
- var _streamTaskWriteClosed: Any?
156
- var _streamTaskBetterRouteDiscovered: Any?
157
- var _streamTaskDidBecomeInputStream: Any?
158
-
159
- #endif
160
-
161
- // MARK: Properties
162
-
163
- var retrier: RequestRetrier?
164
- weak var sessionManager: SessionManager?
165
-
166
- var requests: [Int: Request] = [:]
167
- private let lock = NSLock()
168
-
169
- /// Access the task delegate for the specified task in a thread-safe manner.
170
- open subscript(task: URLSessionTask) -> Request? {
171
- get {
172
- lock.lock() ; defer { lock.unlock() }
173
- return requests[task.taskIdentifier]
174
- }
175
- set {
176
- lock.lock() ; defer { lock.unlock() }
177
- requests[task.taskIdentifier] = newValue
178
- }
179
- }
180
-
181
- // MARK: Lifecycle
182
-
183
- /// Initializes the `SessionDelegate` instance.
184
- ///
185
- /// - returns: The new `SessionDelegate` instance.
186
- public override init() {
187
- super.init()
188
- }
189
-
190
- // MARK: NSObject Overrides
191
-
192
- /// Returns a `Bool` indicating whether the `SessionDelegate` implements or inherits a method that can respond
193
- /// to a specified message.
194
- ///
195
- /// - parameter selector: A selector that identifies a message.
196
- ///
197
- /// - returns: `true` if the receiver implements or inherits a method that can respond to selector, otherwise `false`.
198
- open override func responds(to selector: Selector) -> Bool {
199
- #if !os(macOS)
200
- if selector == #selector(URLSessionDelegate.urlSessionDidFinishEvents(forBackgroundURLSession:)) {
201
- return sessionDidFinishEventsForBackgroundURLSession != nil
202
- }
203
- #endif
204
-
205
- #if !os(watchOS)
206
- if #available(iOS 9.0, macOS 10.11, tvOS 9.0, *) {
207
- switch selector {
208
- case #selector(URLSessionStreamDelegate.urlSession(_:readClosedFor:)):
209
- return streamTaskReadClosed != nil
210
- case #selector(URLSessionStreamDelegate.urlSession(_:writeClosedFor:)):
211
- return streamTaskWriteClosed != nil
212
- case #selector(URLSessionStreamDelegate.urlSession(_:betterRouteDiscoveredFor:)):
213
- return streamTaskBetterRouteDiscovered != nil
214
- case #selector(URLSessionStreamDelegate.urlSession(_:streamTask:didBecome:outputStream:)):
215
- return streamTaskDidBecomeInputAndOutputStreams != nil
216
- default:
217
- break
218
- }
219
- }
220
- #endif
221
-
222
- switch selector {
223
- case #selector(URLSessionDelegate.urlSession(_:didBecomeInvalidWithError:)):
224
- return sessionDidBecomeInvalidWithError != nil
225
- case #selector(URLSessionDelegate.urlSession(_:didReceive:completionHandler:)):
226
- return (sessionDidReceiveChallenge != nil || sessionDidReceiveChallengeWithCompletion != nil)
227
- case #selector(URLSessionTaskDelegate.urlSession(_:task:willPerformHTTPRedirection:newRequest:completionHandler:)):
228
- return (taskWillPerformHTTPRedirection != nil || taskWillPerformHTTPRedirectionWithCompletion != nil)
229
- case #selector(URLSessionDataDelegate.urlSession(_:dataTask:didReceive:completionHandler:)):
230
- return (dataTaskDidReceiveResponse != nil || dataTaskDidReceiveResponseWithCompletion != nil)
231
- default:
232
- return type(of: self).instancesRespond(to: selector)
233
- }
234
- }
235
- }
236
-
237
- // MARK: - URLSessionDelegate
238
-
239
- extension SessionDelegate: URLSessionDelegate {
240
- /// Tells the delegate that the session has been invalidated.
241
- ///
242
- /// - parameter session: The session object that was invalidated.
243
- /// - parameter error: The error that caused invalidation, or nil if the invalidation was explicit.
244
- open func urlSession(_ session: URLSession, didBecomeInvalidWithError error: Error?) {
245
- sessionDidBecomeInvalidWithError?(session, error)
246
- }
247
-
248
- /// Requests credentials from the delegate in response to a session-level authentication request from the
249
- /// remote server.
250
- ///
251
- /// - parameter session: The session containing the task that requested authentication.
252
- /// - parameter challenge: An object that contains the request for authentication.
253
- /// - parameter completionHandler: A handler that your delegate method must call providing the disposition
254
- /// and credential.
255
- open func urlSession(
256
- _ session: URLSession,
257
- didReceive challenge: URLAuthenticationChallenge,
258
- completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void)
259
- {
260
- guard sessionDidReceiveChallengeWithCompletion == nil else {
261
- sessionDidReceiveChallengeWithCompletion?(session, challenge, completionHandler)
262
- return
263
- }
264
-
265
- var disposition: URLSession.AuthChallengeDisposition = .performDefaultHandling
266
- var credential: URLCredential?
267
-
268
- if let sessionDidReceiveChallenge = sessionDidReceiveChallenge {
269
- (disposition, credential) = sessionDidReceiveChallenge(session, challenge)
270
- } else if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust {
271
- let host = challenge.protectionSpace.host
272
-
273
- if
274
- let serverTrustPolicy = session.serverTrustPolicyManager?.serverTrustPolicy(forHost: host),
275
- let serverTrust = challenge.protectionSpace.serverTrust
276
- {
277
- if serverTrustPolicy.evaluate(serverTrust, forHost: host) {
278
- disposition = .useCredential
279
- credential = URLCredential(trust: serverTrust)
280
- } else {
281
- disposition = .cancelAuthenticationChallenge
282
- }
283
- }
284
- }
285
-
286
- completionHandler(disposition, credential)
287
- }
288
-
289
- #if !os(macOS)
290
-
291
- /// Tells the delegate that all messages enqueued for a session have been delivered.
292
- ///
293
- /// - parameter session: The session that no longer has any outstanding requests.
294
- open func urlSessionDidFinishEvents(forBackgroundURLSession session: URLSession) {
295
- sessionDidFinishEventsForBackgroundURLSession?(session)
296
- }
297
-
298
- #endif
299
- }
300
-
301
- // MARK: - URLSessionTaskDelegate
302
-
303
- extension SessionDelegate: URLSessionTaskDelegate {
304
- /// Tells the delegate that the remote server requested an HTTP redirect.
305
- ///
306
- /// - parameter session: The session containing the task whose request resulted in a redirect.
307
- /// - parameter task: The task whose request resulted in a redirect.
308
- /// - parameter response: An object containing the server’s response to the original request.
309
- /// - parameter request: A URL request object filled out with the new location.
310
- /// - parameter completionHandler: A closure that your handler should call with either the value of the request
311
- /// parameter, a modified URL request object, or NULL to refuse the redirect and
312
- /// return the body of the redirect response.
313
- open func urlSession(
314
- _ session: URLSession,
315
- task: URLSessionTask,
316
- willPerformHTTPRedirection response: HTTPURLResponse,
317
- newRequest request: URLRequest,
318
- completionHandler: @escaping (URLRequest?) -> Void)
319
- {
320
- guard taskWillPerformHTTPRedirectionWithCompletion == nil else {
321
- taskWillPerformHTTPRedirectionWithCompletion?(session, task, response, request, completionHandler)
322
- return
323
- }
324
-
325
- var redirectRequest: URLRequest? = request
326
-
327
- if let taskWillPerformHTTPRedirection = taskWillPerformHTTPRedirection {
328
- redirectRequest = taskWillPerformHTTPRedirection(session, task, response, request)
329
- }
330
-
331
- completionHandler(redirectRequest)
332
- }
333
-
334
- /// Requests credentials from the delegate in response to an authentication request from the remote server.
335
- ///
336
- /// - parameter session: The session containing the task whose request requires authentication.
337
- /// - parameter task: The task whose request requires authentication.
338
- /// - parameter challenge: An object that contains the request for authentication.
339
- /// - parameter completionHandler: A handler that your delegate method must call providing the disposition
340
- /// and credential.
341
- open func urlSession(
342
- _ session: URLSession,
343
- task: URLSessionTask,
344
- didReceive challenge: URLAuthenticationChallenge,
345
- completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void)
346
- {
347
- guard taskDidReceiveChallengeWithCompletion == nil else {
348
- taskDidReceiveChallengeWithCompletion?(session, task, challenge, completionHandler)
349
- return
350
- }
351
-
352
- if let taskDidReceiveChallenge = taskDidReceiveChallenge {
353
- let result = taskDidReceiveChallenge(session, task, challenge)
354
- completionHandler(result.0, result.1)
355
- } else if let delegate = self[task]?.delegate {
356
- delegate.urlSession(
357
- session,
358
- task: task,
359
- didReceive: challenge,
360
- completionHandler: completionHandler
361
- )
362
- } else {
363
- urlSession(session, didReceive: challenge, completionHandler: completionHandler)
364
- }
365
- }
366
-
367
- /// Tells the delegate when a task requires a new request body stream to send to the remote server.
368
- ///
369
- /// - parameter session: The session containing the task that needs a new body stream.
370
- /// - parameter task: The task that needs a new body stream.
371
- /// - parameter completionHandler: A completion handler that your delegate method should call with the new body stream.
372
- open func urlSession(
373
- _ session: URLSession,
374
- task: URLSessionTask,
375
- needNewBodyStream completionHandler: @escaping (InputStream?) -> Void)
376
- {
377
- guard taskNeedNewBodyStreamWithCompletion == nil else {
378
- taskNeedNewBodyStreamWithCompletion?(session, task, completionHandler)
379
- return
380
- }
381
-
382
- if let taskNeedNewBodyStream = taskNeedNewBodyStream {
383
- completionHandler(taskNeedNewBodyStream(session, task))
384
- } else if let delegate = self[task]?.delegate {
385
- delegate.urlSession(session, task: task, needNewBodyStream: completionHandler)
386
- }
387
- }
388
-
389
- /// Periodically informs the delegate of the progress of sending body content to the server.
390
- ///
391
- /// - parameter session: The session containing the data task.
392
- /// - parameter task: The data task.
393
- /// - parameter bytesSent: The number of bytes sent since the last time this delegate method was called.
394
- /// - parameter totalBytesSent: The total number of bytes sent so far.
395
- /// - parameter totalBytesExpectedToSend: The expected length of the body data.
396
- open func urlSession(
397
- _ session: URLSession,
398
- task: URLSessionTask,
399
- didSendBodyData bytesSent: Int64,
400
- totalBytesSent: Int64,
401
- totalBytesExpectedToSend: Int64)
402
- {
403
- if let taskDidSendBodyData = taskDidSendBodyData {
404
- taskDidSendBodyData(session, task, bytesSent, totalBytesSent, totalBytesExpectedToSend)
405
- } else if let delegate = self[task]?.delegate as? UploadTaskDelegate {
406
- delegate.URLSession(
407
- session,
408
- task: task,
409
- didSendBodyData: bytesSent,
410
- totalBytesSent: totalBytesSent,
411
- totalBytesExpectedToSend: totalBytesExpectedToSend
412
- )
413
- }
414
- }
415
-
416
- #if !os(watchOS)
417
-
418
- /// Tells the delegate that the session finished collecting metrics for the task.
419
- ///
420
- /// - parameter session: The session collecting the metrics.
421
- /// - parameter task: The task whose metrics have been collected.
422
- /// - parameter metrics: The collected metrics.
423
- @available(iOS 10.0, macOS 10.12, tvOS 10.0, *)
424
- @objc(URLSession:task:didFinishCollectingMetrics:)
425
- open func urlSession(_ session: URLSession, task: URLSessionTask, didFinishCollecting metrics: URLSessionTaskMetrics) {
426
- self[task]?.delegate.metrics = metrics
427
- }
428
-
429
- #endif
430
-
431
- /// Tells the delegate that the task finished transferring data.
432
- ///
433
- /// - parameter session: The session containing the task whose request finished transferring data.
434
- /// - parameter task: The task whose request finished transferring data.
435
- /// - parameter error: If an error occurred, an error object indicating how the transfer failed, otherwise nil.
436
- open func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
437
- /// Executed after it is determined that the request is not going to be retried
438
- let completeTask: (URLSession, URLSessionTask, Error?) -> Void = { [weak self] session, task, error in
439
- guard let strongSelf = self else { return }
440
-
441
- strongSelf.taskDidComplete?(session, task, error)
442
-
443
- strongSelf[task]?.delegate.urlSession(session, task: task, didCompleteWithError: error)
444
-
445
- var userInfo: [String: Any] = [Notification.Key.Task: task]
446
-
447
- if let data = (strongSelf[task]?.delegate as? DataTaskDelegate)?.data {
448
- userInfo[Notification.Key.ResponseData] = data
449
- }
450
-
451
- NotificationCenter.default.post(
452
- name: Notification.Name.Task.DidComplete,
453
- object: strongSelf,
454
- userInfo: userInfo
455
- )
456
-
457
- strongSelf[task] = nil
458
- }
459
-
460
- guard let request = self[task], let sessionManager = sessionManager else {
461
- completeTask(session, task, error)
462
- return
463
- }
464
-
465
- // Run all validations on the request before checking if an error occurred
466
- request.validations.forEach { $0() }
467
-
468
- // Determine whether an error has occurred
469
- var error: Error? = error
470
-
471
- if request.delegate.error != nil {
472
- error = request.delegate.error
473
- }
474
-
475
- /// If an error occurred and the retrier is set, asynchronously ask the retrier if the request
476
- /// should be retried. Otherwise, complete the task by notifying the task delegate.
477
- if let retrier = retrier, let error = error {
478
- retrier.should(sessionManager, retry: request, with: error) { [weak self] shouldRetry, timeDelay in
479
- guard shouldRetry else { completeTask(session, task, error) ; return }
480
-
481
- DispatchQueue.utility.after(timeDelay) { [weak self] in
482
- guard let strongSelf = self else { return }
483
-
484
- let retrySucceeded = strongSelf.sessionManager?.retry(request) ?? false
485
-
486
- if retrySucceeded, let task = request.task {
487
- strongSelf[task] = request
488
- return
489
- } else {
490
- completeTask(session, task, error)
491
- }
492
- }
493
- }
494
- } else {
495
- completeTask(session, task, error)
496
- }
497
- }
498
- }
499
-
500
- // MARK: - URLSessionDataDelegate
501
-
502
- extension SessionDelegate: URLSessionDataDelegate {
503
- /// Tells the delegate that the data task received the initial reply (headers) from the server.
504
- ///
505
- /// - parameter session: The session containing the data task that received an initial reply.
506
- /// - parameter dataTask: The data task that received an initial reply.
507
- /// - parameter response: A URL response object populated with headers.
508
- /// - parameter completionHandler: A completion handler that your code calls to continue the transfer, passing a
509
- /// constant to indicate whether the transfer should continue as a data task or
510
- /// should become a download task.
511
- open func urlSession(
512
- _ session: URLSession,
513
- dataTask: URLSessionDataTask,
514
- didReceive response: URLResponse,
515
- completionHandler: @escaping (URLSession.ResponseDisposition) -> Void)
516
- {
517
- guard dataTaskDidReceiveResponseWithCompletion == nil else {
518
- dataTaskDidReceiveResponseWithCompletion?(session, dataTask, response, completionHandler)
519
- return
520
- }
521
-
522
- var disposition: URLSession.ResponseDisposition = .allow
523
-
524
- if let dataTaskDidReceiveResponse = dataTaskDidReceiveResponse {
525
- disposition = dataTaskDidReceiveResponse(session, dataTask, response)
526
- }
527
-
528
- completionHandler(disposition)
529
- }
530
-
531
- /// Tells the delegate that the data task was changed to a download task.
532
- ///
533
- /// - parameter session: The session containing the task that was replaced by a download task.
534
- /// - parameter dataTask: The data task that was replaced by a download task.
535
- /// - parameter downloadTask: The new download task that replaced the data task.
536
- open func urlSession(
537
- _ session: URLSession,
538
- dataTask: URLSessionDataTask,
539
- didBecome downloadTask: URLSessionDownloadTask)
540
- {
541
- if let dataTaskDidBecomeDownloadTask = dataTaskDidBecomeDownloadTask {
542
- dataTaskDidBecomeDownloadTask(session, dataTask, downloadTask)
543
- } else {
544
- self[downloadTask]?.delegate = DownloadTaskDelegate(task: downloadTask)
545
- }
546
- }
547
-
548
- /// Tells the delegate that the data task has received some of the expected data.
549
- ///
550
- /// - parameter session: The session containing the data task that provided data.
551
- /// - parameter dataTask: The data task that provided data.
552
- /// - parameter data: A data object containing the transferred data.
553
- open func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive data: Data) {
554
- if let dataTaskDidReceiveData = dataTaskDidReceiveData {
555
- dataTaskDidReceiveData(session, dataTask, data)
556
- } else if let delegate = self[dataTask]?.delegate as? DataTaskDelegate {
557
- delegate.urlSession(session, dataTask: dataTask, didReceive: data)
558
- }
559
- }
560
-
561
- /// Asks the delegate whether the data (or upload) task should store the response in the cache.
562
- ///
563
- /// - parameter session: The session containing the data (or upload) task.
564
- /// - parameter dataTask: The data (or upload) task.
565
- /// - parameter proposedResponse: The default caching behavior. This behavior is determined based on the current
566
- /// caching policy and the values of certain received headers, such as the Pragma
567
- /// and Cache-Control headers.
568
- /// - parameter completionHandler: A block that your handler must call, providing either the original proposed
569
- /// response, a modified version of that response, or NULL to prevent caching the
570
- /// response. If your delegate implements this method, it must call this completion
571
- /// handler; otherwise, your app leaks memory.
572
- open func urlSession(
573
- _ session: URLSession,
574
- dataTask: URLSessionDataTask,
575
- willCacheResponse proposedResponse: CachedURLResponse,
576
- completionHandler: @escaping (CachedURLResponse?) -> Void)
577
- {
578
- guard dataTaskWillCacheResponseWithCompletion == nil else {
579
- dataTaskWillCacheResponseWithCompletion?(session, dataTask, proposedResponse, completionHandler)
580
- return
581
- }
582
-
583
- if let dataTaskWillCacheResponse = dataTaskWillCacheResponse {
584
- completionHandler(dataTaskWillCacheResponse(session, dataTask, proposedResponse))
585
- } else if let delegate = self[dataTask]?.delegate as? DataTaskDelegate {
586
- delegate.urlSession(
587
- session,
588
- dataTask: dataTask,
589
- willCacheResponse: proposedResponse,
590
- completionHandler: completionHandler
591
- )
592
- } else {
593
- completionHandler(proposedResponse)
594
- }
595
- }
596
- }
597
-
598
- // MARK: - URLSessionDownloadDelegate
599
-
600
- extension SessionDelegate: URLSessionDownloadDelegate {
601
- /// Tells the delegate that a download task has finished downloading.
602
- ///
603
- /// - parameter session: The session containing the download task that finished.
604
- /// - parameter downloadTask: The download task that finished.
605
- /// - parameter location: A file URL for the temporary file. Because the file is temporary, you must either
606
- /// open the file for reading or move it to a permanent location in your app’s sandbox
607
- /// container directory before returning from this delegate method.
608
- open func urlSession(
609
- _ session: URLSession,
610
- downloadTask: URLSessionDownloadTask,
611
- didFinishDownloadingTo location: URL)
612
- {
613
- if let downloadTaskDidFinishDownloadingToURL = downloadTaskDidFinishDownloadingToURL {
614
- downloadTaskDidFinishDownloadingToURL(session, downloadTask, location)
615
- } else if let delegate = self[downloadTask]?.delegate as? DownloadTaskDelegate {
616
- delegate.urlSession(session, downloadTask: downloadTask, didFinishDownloadingTo: location)
617
- }
618
- }
619
-
620
- /// Periodically informs the delegate about the download’s progress.
621
- ///
622
- /// - parameter session: The session containing the download task.
623
- /// - parameter downloadTask: The download task.
624
- /// - parameter bytesWritten: The number of bytes transferred since the last time this delegate
625
- /// method was called.
626
- /// - parameter totalBytesWritten: The total number of bytes transferred so far.
627
- /// - parameter totalBytesExpectedToWrite: The expected length of the file, as provided by the Content-Length
628
- /// header. If this header was not provided, the value is
629
- /// `NSURLSessionTransferSizeUnknown`.
630
- open func urlSession(
631
- _ session: URLSession,
632
- downloadTask: URLSessionDownloadTask,
633
- didWriteData bytesWritten: Int64,
634
- totalBytesWritten: Int64,
635
- totalBytesExpectedToWrite: Int64)
636
- {
637
- if let downloadTaskDidWriteData = downloadTaskDidWriteData {
638
- downloadTaskDidWriteData(session, downloadTask, bytesWritten, totalBytesWritten, totalBytesExpectedToWrite)
639
- } else if let delegate = self[downloadTask]?.delegate as? DownloadTaskDelegate {
640
- delegate.urlSession(
641
- session,
642
- downloadTask: downloadTask,
643
- didWriteData: bytesWritten,
644
- totalBytesWritten: totalBytesWritten,
645
- totalBytesExpectedToWrite: totalBytesExpectedToWrite
646
- )
647
- }
648
- }
649
-
650
- /// Tells the delegate that the download task has resumed downloading.
651
- ///
652
- /// - parameter session: The session containing the download task that finished.
653
- /// - parameter downloadTask: The download task that resumed. See explanation in the discussion.
654
- /// - parameter fileOffset: If the file's cache policy or last modified date prevents reuse of the
655
- /// existing content, then this value is zero. Otherwise, this value is an
656
- /// integer representing the number of bytes on disk that do not need to be
657
- /// retrieved again.
658
- /// - parameter expectedTotalBytes: The expected length of the file, as provided by the Content-Length header.
659
- /// If this header was not provided, the value is NSURLSessionTransferSizeUnknown.
660
- open func urlSession(
661
- _ session: URLSession,
662
- downloadTask: URLSessionDownloadTask,
663
- didResumeAtOffset fileOffset: Int64,
664
- expectedTotalBytes: Int64)
665
- {
666
- if let downloadTaskDidResumeAtOffset = downloadTaskDidResumeAtOffset {
667
- downloadTaskDidResumeAtOffset(session, downloadTask, fileOffset, expectedTotalBytes)
668
- } else if let delegate = self[downloadTask]?.delegate as? DownloadTaskDelegate {
669
- delegate.urlSession(
670
- session,
671
- downloadTask: downloadTask,
672
- didResumeAtOffset: fileOffset,
673
- expectedTotalBytes: expectedTotalBytes
674
- )
675
- }
676
- }
677
- }
678
-
679
- // MARK: - URLSessionStreamDelegate
680
-
681
- #if !os(watchOS)
682
-
683
- @available(iOS 9.0, macOS 10.11, tvOS 9.0, *)
684
- extension SessionDelegate: URLSessionStreamDelegate {
685
- /// Tells the delegate that the read side of the connection has been closed.
686
- ///
687
- /// - parameter session: The session.
688
- /// - parameter streamTask: The stream task.
689
- open func urlSession(_ session: URLSession, readClosedFor streamTask: URLSessionStreamTask) {
690
- streamTaskReadClosed?(session, streamTask)
691
- }
692
-
693
- /// Tells the delegate that the write side of the connection has been closed.
694
- ///
695
- /// - parameter session: The session.
696
- /// - parameter streamTask: The stream task.
697
- open func urlSession(_ session: URLSession, writeClosedFor streamTask: URLSessionStreamTask) {
698
- streamTaskWriteClosed?(session, streamTask)
699
- }
700
-
701
- /// Tells the delegate that the system has determined that a better route to the host is available.
702
- ///
703
- /// - parameter session: The session.
704
- /// - parameter streamTask: The stream task.
705
- open func urlSession(_ session: URLSession, betterRouteDiscoveredFor streamTask: URLSessionStreamTask) {
706
- streamTaskBetterRouteDiscovered?(session, streamTask)
707
- }
708
-
709
- /// Tells the delegate that the stream task has been completed and provides the unopened stream objects.
710
- ///
711
- /// - parameter session: The session.
712
- /// - parameter streamTask: The stream task.
713
- /// - parameter inputStream: The new input stream.
714
- /// - parameter outputStream: The new output stream.
715
- open func urlSession(
716
- _ session: URLSession,
717
- streamTask: URLSessionStreamTask,
718
- didBecome inputStream: InputStream,
719
- outputStream: OutputStream)
720
- {
721
- streamTaskDidBecomeInputAndOutputStreams?(session, streamTask, inputStream, outputStream)
722
- }
723
- }
724
-
725
- #endif