<!--
{
  "availability" : [

  ],
  "documentType" : "symbol",
  "framework" : "Tor",
  "identifier" : "/documentation/Tor/Foundation/URLSessionConfiguration/configuredForTor(socksEndpoint:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Tor",
      "Foundation"
    ],
    "preciseIdentifier" : "s:So25NSURLSessionConfigurationC3TorE013configuredForC013socksEndpointAbC8HostPortV_tFZ"
  },
  "title" : "configuredForTor(socksEndpoint:)"
}
-->

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

```swift
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
> ``doc://Tor/documentation/Tor/Foundation/URLSessionConfiguration/ephemeralConfiguredForTor(socksEndpoint:)`` instead.