{
  "type": "module",
  "source": "doc/api/api-socks5proxyagent.md",
  "modules": [
    {
      "textRaw": "Class: Socks5ProxyAgent",
      "name": "class:_socks5proxyagent",
      "type": "module",
      "desc": "<p>Extends: <code>undici.Dispatcher</code></p>\n<p>A SOCKS5 proxy wrapper class that implements the Dispatcher API. It enables HTTP requests to be routed through a SOCKS5 proxy server, providing connection tunneling and authentication support.</p>",
      "signatures": [
        {
          "textRaw": "`new Socks5ProxyAgent(proxyUrl[, options])`",
          "name": "Socks5ProxyAgent",
          "type": "ctor",
          "params": [
            {
              "name": "proxyUrl"
            },
            {
              "name": "options",
              "optional": true
            }
          ],
          "desc": "<p>Arguments:</p>\n<ul>\n<li><strong>proxyUrl</strong> <code>string | URL</code> (required) - The SOCKS5 proxy server URL. Must use <code>socks5://</code> or <code>socks://</code> protocol.</li>\n<li><strong>options</strong> <code>Socks5ProxyAgent.Options</code> (optional) - Additional configuration options.</li>\n</ul>\n<p>Returns: <code>Socks5ProxyAgent</code></p>",
          "modules": [
            {
              "textRaw": "Parameter: `Socks5ProxyAgent.Options`",
              "name": "parameter:_`socks5proxyagent.options`",
              "type": "module",
              "desc": "<p>Extends: <a href=\"/docs/docs/api/Pool.html#parameter-pooloptions\"><code>PoolOptions</code></a></p>\n<ul>\n<li><strong>headers</strong> <code>IncomingHttpHeaders</code> (optional) - Additional headers to send with proxy connections.</li>\n<li><strong>username</strong> <code>string</code> (optional) - SOCKS5 proxy username for authentication. Can also be provided in the proxy URL.</li>\n<li><strong>password</strong> <code>string</code> (optional) - SOCKS5 proxy password for authentication. Can also be provided in the proxy URL.</li>\n<li><strong>connect</strong> <code>Function</code> (optional) - Custom connector function for the proxy connection.</li>\n<li><strong>proxyTls</strong> <code>BuildOptions</code> (optional) - TLS options for the proxy connection (when using SOCKS5 over TLS).</li>\n<li><strong>requestTls</strong> <code>BuildOptions</code> (optional) - TLS options applied to the HTTPS connection to the target server through the SOCKS5 tunnel. Use this to configure <code>ca</code>, <code>cert</code>, <code>key</code>, <code>rejectUnauthorized</code>, <code>servername</code>, etc. for the target HTTPS endpoint.</li>\n</ul>\n<p>Examples:</p>\n<pre><code class=\"language-js\">import { Socks5ProxyAgent } from 'undici'\n\nconst socks5Proxy = new Socks5ProxyAgent('socks5://localhost:1080')\n// or with authentication\nconst socks5ProxyWithAuth = new Socks5ProxyAgent('socks5://user:pass@localhost:1080')\n// or with options\nconst socks5ProxyWithOptions = new Socks5ProxyAgent('socks5://localhost:1080', {\n  username: 'user',\n  password: 'pass',\n  connections: 10\n})\n</code></pre>",
              "modules": [
                {
                  "textRaw": "Example - Basic SOCKS5 Proxy instantiation",
                  "name": "example_-_basic_socks5_proxy_instantiation",
                  "type": "module",
                  "desc": "<p>This will instantiate the Socks5ProxyAgent. It will not do anything until registered as the dispatcher to use with requests.</p>\n<pre><code class=\"language-js\">import { Socks5ProxyAgent } from 'undici'\n\nconst socks5Proxy = new Socks5ProxyAgent('socks5://localhost:1080')\n</code></pre>",
                  "displayName": "Example - Basic SOCKS5 Proxy instantiation"
                },
                {
                  "textRaw": "Example - Basic SOCKS5 Proxy Request with global dispatcher",
                  "name": "example_-_basic_socks5_proxy_request_with_global_dispatcher",
                  "type": "module",
                  "desc": "<pre><code class=\"language-js\">import { setGlobalDispatcher, request, Socks5ProxyAgent } from 'undici'\n\nconst socks5Proxy = new Socks5ProxyAgent('socks5://localhost:1080')\nsetGlobalDispatcher(socks5Proxy)\n\nconst { statusCode, body } = await request('http://localhost:3000/foo')\n\nconsole.log('response received', statusCode) // response received 200\n\nfor await (const data of body) {\n  console.log('data', data.toString('utf8')) // data foo\n}\n</code></pre>",
                  "displayName": "Example - Basic SOCKS5 Proxy Request with global dispatcher"
                },
                {
                  "textRaw": "Example - Basic SOCKS5 Proxy Request with local dispatcher",
                  "name": "example_-_basic_socks5_proxy_request_with_local_dispatcher",
                  "type": "module",
                  "desc": "<pre><code class=\"language-js\">import { Socks5ProxyAgent, request } from 'undici'\n\nconst socks5Proxy = new Socks5ProxyAgent('socks5://localhost:1080')\n\nconst {\n  statusCode,\n  body\n} = await request('http://localhost:3000/foo', { dispatcher: socks5Proxy })\n\nconsole.log('response received', statusCode) // response received 200\n\nfor await (const data of body) {\n  console.log('data', data.toString('utf8')) // data foo\n}\n</code></pre>",
                  "displayName": "Example - Basic SOCKS5 Proxy Request with local dispatcher"
                },
                {
                  "textRaw": "Example - SOCKS5 Proxy Request with authentication",
                  "name": "example_-_socks5_proxy_request_with_authentication",
                  "type": "module",
                  "desc": "<pre><code class=\"language-js\">import { setGlobalDispatcher, request, Socks5ProxyAgent } from 'undici'\n\n// Authentication via URL\nconst socks5Proxy = new Socks5ProxyAgent('socks5://username:password@localhost:1080')\n\n// Or authentication via options\n// const socks5Proxy = new Socks5ProxyAgent('socks5://localhost:1080', {\n//   username: 'username',\n//   password: 'password'\n// })\n\nsetGlobalDispatcher(socks5Proxy)\n\nconst { statusCode, body } = await request('http://localhost:3000/foo')\n\nconsole.log('response received', statusCode) // response received 200\n\nfor await (const data of body) {\n  console.log('data', data.toString('utf8')) // data foo\n}\n</code></pre>",
                  "displayName": "Example - SOCKS5 Proxy Request with authentication"
                },
                {
                  "textRaw": "Example - SOCKS5 Proxy with HTTPS requests",
                  "name": "example_-_socks5_proxy_with_https_requests",
                  "type": "module",
                  "desc": "<p>SOCKS5 proxy supports both HTTP and HTTPS requests through tunneling:</p>\n<pre><code class=\"language-js\">import { Socks5ProxyAgent, request } from 'undici'\n\nconst socks5Proxy = new Socks5ProxyAgent('socks5://localhost:1080')\n\nconst response = await request('https://api.example.com/data', {\n  dispatcher: socks5Proxy,\n  method: 'GET'\n})\n\nconsole.log('Response status:', response.statusCode)\nconsole.log('Response data:', await response.body.json())\n</code></pre>",
                  "displayName": "Example - SOCKS5 Proxy with HTTPS requests"
                },
                {
                  "textRaw": "Example - SOCKS5 Proxy with Fetch",
                  "name": "example_-_socks5_proxy_with_fetch",
                  "type": "module",
                  "desc": "<pre><code class=\"language-js\">import { Socks5ProxyAgent, fetch } from 'undici'\n\nconst socks5Proxy = new Socks5ProxyAgent('socks5://localhost:1080')\n\nconst response = await fetch('http://localhost:3000/api/users', {\n  dispatcher: socks5Proxy,\n  method: 'GET'\n})\n\nconsole.log('Response status:', response.status)\nconsole.log('Response data:', await response.text())\n</code></pre>",
                  "displayName": "Example - SOCKS5 Proxy with Fetch"
                },
                {
                  "textRaw": "Example - Connection Pooling",
                  "name": "example_-_connection_pooling",
                  "type": "module",
                  "desc": "<p>SOCKS5ProxyWrapper automatically manages connection pooling for better performance:</p>\n<pre><code class=\"language-js\">import { Socks5ProxyAgent, request } from 'undici'\n\nconst socks5Proxy = new Socks5ProxyAgent('socks5://localhost:1080', {\n  connections: 10, // Allow up to 10 concurrent connections\n  pipelining: 1    // Enable HTTP/1.1 pipelining\n})\n\n// Multiple requests will reuse connections through the SOCKS5 tunnel\nconst responses = await Promise.all([\n  request('http://api.example.com/endpoint1', { dispatcher: socks5Proxy }),\n  request('http://api.example.com/endpoint2', { dispatcher: socks5Proxy }),\n  request('http://api.example.com/endpoint3', { dispatcher: socks5Proxy })\n])\n\nconsole.log('All requests completed through the same SOCKS5 proxy')\n</code></pre>",
                  "displayName": "Example - Connection Pooling"
                }
              ],
              "displayName": "Parameter: `Socks5ProxyAgent.Options`"
            }
          ],
          "methods": [
            {
              "textRaw": "`Socks5ProxyAgent.close()`",
              "name": "close",
              "type": "method",
              "signatures": [
                {
                  "params": []
                }
              ],
              "desc": "<p>Closes the SOCKS5 proxy wrapper and waits for all underlying pools and connections to close before resolving.</p>\n<p>Returns: <code>Promise&#x3C;void></code></p>",
              "modules": [
                {
                  "textRaw": "Example - clean up after tests are complete",
                  "name": "example_-_clean_up_after_tests_are_complete",
                  "type": "module",
                  "desc": "<pre><code class=\"language-js\">import { Socks5ProxyAgent, setGlobalDispatcher } from 'undici'\n\nconst socks5Proxy = new Socks5ProxyAgent('socks5://localhost:1080')\nsetGlobalDispatcher(socks5Proxy)\n\n// ... make requests\n\nawait socks5Proxy.close()\n</code></pre>",
                  "displayName": "Example - clean up after tests are complete"
                }
              ]
            },
            {
              "textRaw": "`Socks5ProxyAgent.destroy([err])`",
              "name": "destroy",
              "type": "method",
              "signatures": [
                {
                  "params": [
                    {
                      "name": "err",
                      "optional": true
                    }
                  ]
                }
              ],
              "desc": "<p>Destroys the SOCKS5 proxy wrapper and all underlying connections immediately.</p>\n<p>Arguments:</p>\n<ul>\n<li><strong>err</strong> <code>Error</code> (optional) - The error that caused the destruction.</li>\n</ul>\n<p>Returns: <code>Promise&#x3C;void></code></p>",
              "modules": [
                {
                  "textRaw": "Example - force close all connections",
                  "name": "example_-_force_close_all_connections",
                  "type": "module",
                  "desc": "<pre><code class=\"language-js\">import { Socks5ProxyAgent } from 'undici'\n\nconst socks5Proxy = new Socks5ProxyAgent('socks5://localhost:1080')\n\n// Force close all connections\nawait socks5Proxy.destroy()\n</code></pre>",
                  "displayName": "Example - force close all connections"
                }
              ]
            },
            {
              "textRaw": "`Socks5ProxyAgent.dispatch(options, handlers)`",
              "name": "dispatch",
              "type": "method",
              "signatures": [
                {
                  "params": [
                    {
                      "name": "options"
                    },
                    {
                      "name": "handlers"
                    }
                  ]
                }
              ],
              "desc": "<p>Implements <a href=\"/docs/docs/api/Dispatcher.html#dispatcherdispatchoptions-handlers\"><code>Dispatcher.dispatch(options, handlers)</code></a>.</p>"
            },
            {
              "textRaw": "`Socks5ProxyAgent.request(options[, callback])`",
              "name": "request",
              "type": "method",
              "signatures": [
                {
                  "params": [
                    {
                      "name": "options"
                    },
                    {
                      "name": "callback",
                      "optional": true
                    }
                  ]
                }
              ],
              "desc": "<p>See <a href=\"/docs/docs/api/Dispatcher.html#dispatcherrequestoptions-callback\"><code>Dispatcher.request(options [, callback])</code></a>.</p>"
            }
          ]
        }
      ],
      "modules": [
        {
          "textRaw": "Debugging",
          "name": "debugging",
          "type": "module",
          "desc": "<p>SOCKS5 proxy connections can be debugged using Node.js diagnostics:</p>\n<pre><code class=\"language-sh\">NODE_DEBUG=undici:socks5 node script.js\n</code></pre>\n<p>This will output detailed information about the SOCKS5 handshake, authentication, and connection establishment.</p>",
          "displayName": "Debugging"
        },
        {
          "textRaw": "SOCKS5 Protocol Support",
          "name": "socks5_protocol_support",
          "type": "module",
          "desc": "<p>The Socks5ProxyAgent supports the following SOCKS5 features:</p>",
          "modules": [
            {
              "textRaw": "Authentication Methods",
              "name": "authentication_methods",
              "type": "module",
              "desc": "<ul>\n<li><strong>No Authentication</strong> (<code>0x00</code>) - For public or internal proxies</li>\n<li><strong>Username/Password</strong> (<code>0x02</code>) - RFC 1929 authentication</li>\n</ul>",
              "displayName": "Authentication Methods"
            },
            {
              "textRaw": "Address Types",
              "name": "address_types",
              "type": "module",
              "desc": "<ul>\n<li><strong>IPv4</strong> (<code>0x01</code>) - Standard IPv4 addresses</li>\n<li><strong>Domain Name</strong> (<code>0x03</code>) - Domain names (recommended for flexibility)</li>\n<li><strong>IPv6</strong> (<code>0x04</code>) - IPv6 addresses (full support for standard and compressed notation)</li>\n</ul>",
              "displayName": "Address Types"
            },
            {
              "textRaw": "Commands",
              "name": "commands",
              "type": "module",
              "desc": "<ul>\n<li><strong>CONNECT</strong> (<code>0x01</code>) - Establish TCP connection (primary use case for HTTP)</li>\n</ul>",
              "displayName": "Commands"
            },
            {
              "textRaw": "Error Handling",
              "name": "error_handling",
              "type": "module",
              "desc": "<p>The wrapper handles various SOCKS5 error conditions:</p>\n<ul>\n<li>Connection refused by proxy</li>\n<li>Authentication failures</li>\n<li>Network unreachable</li>\n<li>Host unreachable</li>\n<li>Unsupported address types or commands</li>\n</ul>",
              "displayName": "Error Handling"
            }
          ],
          "displayName": "SOCKS5 Protocol Support"
        },
        {
          "textRaw": "Performance Considerations",
          "name": "performance_considerations",
          "type": "module",
          "desc": "<ul>\n<li><strong>Connection Pooling</strong>: Automatically pools connections through the SOCKS5 tunnel for better performance</li>\n<li><strong>HTTP/1.1 Pipelining</strong>: Supports pipelining when enabled</li>\n<li><strong>DNS Resolution</strong>: Domain names are resolved by the SOCKS5 proxy, reducing local DNS queries</li>\n<li><strong>TLS Termination</strong>: HTTPS connections are encrypted end-to-end, with the SOCKS5 proxy only handling the TCP tunnel</li>\n</ul>",
          "displayName": "Performance Considerations"
        },
        {
          "textRaw": "Security Notes",
          "name": "security_notes",
          "type": "module",
          "desc": "<ol>\n<li><strong>Authentication</strong>: Credentials are sent to the SOCKS5 proxy in plaintext unless using SOCKS5 over TLS</li>\n<li><strong>DNS Leaks</strong>: All DNS resolution happens on the proxy server, preventing DNS leaks</li>\n<li><strong>End-to-end Encryption</strong>: HTTPS traffic remains encrypted between client and final destination</li>\n<li><strong>Connection Security</strong>: Consider using authenticated proxies and secure networks</li>\n</ol>",
          "displayName": "Security Notes"
        },
        {
          "textRaw": "Compatibility",
          "name": "compatibility",
          "type": "module",
          "desc": "<ul>\n<li><strong>Protocol</strong>: SOCKS5 (RFC 1928) with Username/Password Authentication (RFC 1929)</li>\n<li><strong>Transport</strong>: TCP only (UDP support not implemented)</li>\n<li><strong>Node.js</strong>: Compatible with all supported Node.js versions</li>\n<li><strong>HTTP Versions</strong>: Works with HTTP/1.1 and HTTP/2 over the tunnel</li>\n</ul>",
          "displayName": "Compatibility"
        }
      ],
      "displayName": "Class: Socks5ProxyAgent"
    }
  ]
}