@@ -13,23 +13,21 @@ import Dispatch
13
13
internal class _HTTPURLProtocol : URLProtocol {
14
14
15
15
fileprivate var easyHandle : _EasyHandle !
16
- fileprivate var tempFileURL : URL
16
+ fileprivate lazy var tempFileURL : URL = {
17
+ let fileName = NSTemporaryDirectory ( ) + NSUUID( ) . uuidString + " .tmp "
18
+ _ = FileManager . default. createFile ( atPath: fileName, contents: nil )
19
+ return URL ( fileURLWithPath: fileName)
20
+ } ( )
17
21
18
22
public required init ( task: URLSessionTask , cachedResponse: CachedURLResponse ? , client: URLProtocolClient ? ) {
19
23
self . internalState = _InternalState. initial
20
- let fileName = NSTemporaryDirectory ( ) + NSUUID( ) . uuidString + " .tmp "
21
- _ = FileManager . default. createFile ( atPath: fileName, contents: nil )
22
- self . tempFileURL = URL ( fileURLWithPath: fileName)
23
24
super. init ( request: task. originalRequest!, cachedResponse: cachedResponse, client: client)
24
25
self . task = task
25
26
self . easyHandle = _EasyHandle ( delegate: self )
26
27
}
27
28
28
29
public required init ( request: URLRequest , cachedResponse: CachedURLResponse ? , client: URLProtocolClient ? ) {
29
30
self . internalState = _InternalState. initial
30
- let fileName = NSTemporaryDirectory ( ) + NSUUID( ) . uuidString + " .tmp "
31
- _ = FileManager . default. createFile ( atPath: fileName, contents: nil )
32
- self . tempFileURL = URL ( fileURLWithPath: fileName)
33
31
super. init ( request: request, cachedResponse: cachedResponse, client: client)
34
32
self . easyHandle = _EasyHandle ( delegate: self )
35
33
}
0 commit comments