<!--
{
  "availability" : [

  ],
  "documentType" : "symbol",
  "framework" : "Tor",
  "identifier" : "/documentation/Tor/TorClient/makeURLSession(ephemeral:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Tor"
    ],
    "preciseIdentifier" : "s:3Tor0A6ClientC14makeURLSession9ephemeralSo12NSURLSessionCSb_tYaKF"
  },
  "title" : "makeURLSession(ephemeral:)"
}
-->

# 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`](/documentation/Tor/TorClient/socksEndpoint).

## Discussion

Gates on [`state`](/documentation/Tor/TorClient/state) being [`TorState.running`](/documentation/Tor/TorState/running) and
[`socksEndpoint`](/documentation/Tor/TorClient/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: ``doc://Tor/documentation/Tor/TorError/notStarted`` when ``doc://Tor/documentation/Tor/TorClient/state`` is not
> operational; ``doc://Tor/documentation/Tor/TorError/controlUnavailable`` when the SOCKS
> endpoint has not yet been discovered.

> Important: Only call after
> ``doc://Tor/documentation/Tor/TorClient/waitUntilBootstrapped(timeout:)`` has returned; until
> Tor reaches 100% bootstrap, traffic through the returned
> session will fail with `NSURLErrorNetworkConnectionLost`
> or similar.