Type Method
configuredForTor(socksEndpoint:)
Build a persistent URLSessionConfiguration that routes every HTTP/HTTPS request through a SOCKS5 proxy.
static func configuredForTor(socksEndpoint endpoint: HostPort) -> URLSessionConfiguration
Parameters
-
endpoint
-
SOCKS5 proxy endpoint, typically socksEndpoint.
Return Value
A configuration with the SOCKS5 proxy installed. All other defaults of URLSessionConfiguration.default are preserved.
Discussion
Starts from URLSessionConfiguration.default (which persists cookies, caches, and credentials to disk) and installs a SOCKS5 proxy dictionary pointing at endpoint. Suitable for long-lived sessions where Apple’s default URL loading behaviour — HTTP pipelining, URL cache, cookie storage — is desired.
Example
let client = TorClient(configuration: .ephemeral())
try await client.start()
try await client.waitUntilBootstrapped()
let config = URLSessionConfiguration.configuredForTor(
socksEndpoint: await client.socksEndpoint!
)
let session = URLSession(configuration: config)
let (data, _) = try await session.data(
from: URL(string: "https://check.torproject.org/api/ip")!
)
Important
The returned configuration persists cookies, caches, and credentials to disk via the default shared containers. For privacy-sensitive sessions, use ephemeralConfiguredForTor(socksEndpoint:) instead.