blob: d8ebda1921206f8b7595981dd60273f77f9ef846 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
//
// URLSessionTransport.swift
// MullvadTransport
//
// Created by Mojgan on 2023-12-08.
// Copyright © 2025 Mullvad VPN AB. All rights reserved.
//
import Foundation
import MullvadTypes
struct URLSessionTaskWrapper: Cancellable {
let task: URLSessionTask
func cancel() {
task.cancel()
}
}
public final class URLSessionTransport: RESTTransport {
public var name: String {
"url-session"
}
public let urlSession: URLSession
public init(urlSession: URLSession) {
self.urlSession = urlSession
}
public func sendRequest(
_ request: URLRequest,
completion: @escaping @Sendable (Data?, URLResponse?, Swift.Error?) -> Void
) -> Cancellable {
let dataTask = urlSession.dataTask(with: request, completionHandler: completion)
dataTask.resume()
return URLSessionTaskWrapper(task: dataTask)
}
}
|