@@ -281,7 +281,7 @@ open class URLSession : NSObject {
281
281
*/
282
282
283
283
/* Creates a data task with the given request. The request may have a body stream. */
284
- open func dataTask( with request: NSURLRequest ) -> URLSessionDataTask {
284
+ open func dataTask( with request: URLRequest ) -> URLSessionDataTask {
285
285
return dataTask ( with: _Request ( request) , behaviour: . callDelegate)
286
286
}
287
287
@@ -291,22 +291,22 @@ open class URLSession : NSObject {
291
291
}
292
292
293
293
/* Creates an upload task with the given request. The body of the request will be created from the file referenced by fileURL */
294
- open func uploadTask( with request: NSURLRequest , fromFile fileURL: URL ) -> URLSessionUploadTask {
294
+ open func uploadTask( with request: URLRequest , fromFile fileURL: URL ) -> URLSessionUploadTask {
295
295
let r = URLSession . _Request ( request)
296
296
return uploadTask ( with: r, body: . file( fileURL) , behaviour: . callDelegate)
297
297
}
298
298
299
299
/* Creates an upload task with the given request. The body of the request is provided from the bodyData. */
300
- open func uploadTask( with request: NSURLRequest , fromData bodyData: Data ) -> URLSessionUploadTask {
300
+ open func uploadTask( with request: URLRequest , fromData bodyData: Data ) -> URLSessionUploadTask {
301
301
let r = URLSession . _Request ( request)
302
302
return uploadTask ( with: r, body: . data( createDispatchData ( bodyData) ) , behaviour: . callDelegate)
303
303
}
304
304
305
305
/* Creates an upload task with the given request. The previously set body stream of the request (if any) is ignored and the URLSession:task:needNewBodyStream: delegate will be called when the body payload is required. */
306
- open func uploadTask( withStreamedRequest request: NSURLRequest ) -> URLSessionUploadTask { NSUnimplemented ( ) }
306
+ open func uploadTask( withStreamedRequest request: URLRequest ) -> URLSessionUploadTask { NSUnimplemented ( ) }
307
307
308
308
/* Creates a download task with the given request. */
309
- open func downloadTask( with request: NSURLRequest ) -> URLSessionDownloadTask {
309
+ open func downloadTask( with request: URLRequest ) -> URLSessionDownloadTask {
310
310
let r = URLSession . _Request ( request)
311
311
return downloadTask ( with: r, behavior: . callDelegate)
312
312
}
@@ -328,10 +328,10 @@ open class URLSession : NSObject {
328
328
// Helpers
329
329
fileprivate extension URLSession {
330
330
enum _Request {
331
- case request( NSURLRequest )
331
+ case request( URLRequest )
332
332
case url( URL )
333
333
}
334
- func createConfiguredRequest( from request: URLSession . _Request ) -> NSURLRequest {
334
+ func createConfiguredRequest( from request: URLSession . _Request ) -> URLRequest {
335
335
let r = request. createMutableURLRequest ( )
336
336
_configuration. configure ( request: r)
337
337
return r
@@ -341,15 +341,15 @@ extension URLSession._Request {
341
341
init ( _ url: URL ) {
342
342
self = . url( url)
343
343
}
344
- init ( _ request: NSURLRequest ) {
344
+ init ( _ request: URLRequest ) {
345
345
self = . request( request)
346
346
}
347
347
}
348
348
extension URLSession . _Request {
349
- func createMutableURLRequest( ) -> NSMutableURLRequest {
349
+ func createMutableURLRequest( ) -> URLRequest {
350
350
switch self {
351
- case . url( let url) : return NSMutableURLRequest ( url: url)
352
- case . request( let r) : return r. mutableCopy ( ) as! NSMutableURLRequest
351
+ case . url( let url) : return URLRequest ( url: url)
352
+ case . request( let r) : return r
353
353
}
354
354
}
355
355
}
@@ -420,7 +420,7 @@ extension URLSession {
420
420
* see <Foundation/NSURLError.h>. The delegate, if any, will still be
421
421
* called for authentication challenges.
422
422
*/
423
- open func dataTask( with request: NSURLRequest , completionHandler: @escaping ( Data ? , URLResponse ? , NSError ? ) -> Void ) -> URLSessionDataTask {
423
+ open func dataTask( with request: URLRequest , completionHandler: @escaping ( Data ? , URLResponse ? , NSError ? ) -> Void ) -> URLSessionDataTask {
424
424
return dataTask ( with: _Request ( request) , behaviour: . dataCompletionHandler( completionHandler) )
425
425
}
426
426
@@ -431,12 +431,12 @@ extension URLSession {
431
431
/*
432
432
* upload convenience method.
433
433
*/
434
- open func uploadTask( with request: NSURLRequest , fromFile fileURL: URL , completionHandler: @escaping ( Data ? , URLResponse ? , NSError ? ) -> Void ) -> URLSessionUploadTask {
434
+ open func uploadTask( with request: URLRequest , fromFile fileURL: URL , completionHandler: @escaping ( Data ? , URLResponse ? , NSError ? ) -> Void ) -> URLSessionUploadTask {
435
435
let fileData = try ! Data ( contentsOf: fileURL)
436
436
return uploadTask ( with: request, fromData: fileData, completionHandler: completionHandler)
437
437
}
438
438
439
- open func uploadTask( with request: NSURLRequest , fromData bodyData: Data ? , completionHandler: @escaping ( Data ? , URLResponse ? , NSError ? ) -> Void ) -> URLSessionUploadTask {
439
+ open func uploadTask( with request: URLRequest , fromData bodyData: Data ? , completionHandler: @escaping ( Data ? , URLResponse ? , NSError ? ) -> Void ) -> URLSessionUploadTask {
440
440
return uploadTask ( with: _Request ( request) , body: . data( createDispatchData ( bodyData!) ) , behaviour: . dataCompletionHandler( completionHandler) )
441
441
}
442
442
@@ -446,7 +446,7 @@ extension URLSession {
446
446
* copied during the invocation of the completion routine. The file
447
447
* will be removed automatically.
448
448
*/
449
- open func downloadTask( with request: NSURLRequest , completionHandler: @escaping ( URL ? , URLResponse ? , NSError ? ) -> Void ) -> URLSessionDownloadTask {
449
+ open func downloadTask( with request: URLRequest , completionHandler: @escaping ( URL ? , URLResponse ? , NSError ? ) -> Void ) -> URLSessionDownloadTask {
450
450
return downloadTask ( with: _Request ( request) , behavior: . downloadCompletionHandler( completionHandler) )
451
451
}
452
452
0 commit comments