Instance Method
makeURLSession(ephemeral:)
Return a ready-to-use URLSession that routes every request through this Tor instance’s SOCKS5 proxy.
func makeURLSession(ephemeral: Bool = false) async throws -> URLSession
Parameters
-
ephemeral
-
When true, uses the ephemeral configuration (no disk persistence). Defaults to false.
Return Value
A configured URLSession backed by the SOCKS5 proxy at socksEndpoint.
Discussion
Gates on state being TorState.running and socksEndpoint being non-nil, then delegates to URLSessionConfiguration.configuredForTor(socksEndpoint:) (or URLSessionConfiguration.ephemeralConfiguredForTor(socksEndpoint:) when ephemeral is true). Avoids the boilerplate of unwrapping socksEndpoint at every call site.
Throws
TorError.notStarted when state is not operational; TorError.controlUnavailable when the SOCKS endpoint has not yet been discovered.
Important
Only call after waitUntilBootstrapped(timeout:) has returned; until Tor reaches 100% bootstrap, traffic through the returned session will fail with NSURLErrorNetworkConnectionLost or similar.