@openclaw/discord 2026.6.33 → 2026.6.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/dist/api.js +1 -1
  2. package/dist/{channel-Ddnonoy4.js → channel-DU4jnQgl.js} +1 -1
  3. package/dist/channel-plugin-api.js +1 -1
  4. package/dist/{manager.runtime-BK6cf2Zu.js → manager.runtime-NxCd-PVt.js} +1 -1
  5. package/dist/{message-handler-BqpJIavO.js → message-handler-cizxbaDc.js} +3 -2
  6. package/dist/{message-handler.preflight-C90MxCcv.js → message-handler.preflight-CbD0u7U7.js} +2 -2
  7. package/dist/{message-handler.process-CeQ7Bd_3.js → message-handler.process-Do4EM591.js} +2 -2
  8. package/dist/{provider-C7376XFH.js → provider-B-s93q9s.js} +31 -6
  9. package/dist/{provider-session.runtime-CCdqogGf.js → provider-session.runtime-BKMOqHpd.js} +1 -1
  10. package/dist/provider.runtime-CaTJrpnl.js +2 -0
  11. package/dist/runtime-api.js +3 -3
  12. package/dist/{runtime-api.monitor-4oc58TSk.js → runtime-api.monitor-CRiBIQEI.js} +2 -2
  13. package/dist/runtime-api.monitor.js +3 -3
  14. package/node_modules/undici/README.md +8 -2
  15. package/node_modules/undici/docs/docs/api/Agent.md +248 -44
  16. package/node_modules/undici/docs/docs/api/BalancedPool.md +246 -48
  17. package/node_modules/undici/docs/docs/api/CacheStorage.md +171 -13
  18. package/node_modules/undici/docs/docs/api/CacheStore.md +294 -98
  19. package/node_modules/undici/docs/docs/api/Client.md +369 -179
  20. package/node_modules/undici/docs/docs/api/ClientStats.md +80 -14
  21. package/node_modules/undici/docs/docs/api/Connector.md +118 -36
  22. package/node_modules/undici/docs/docs/api/ContentType.md +65 -25
  23. package/node_modules/undici/docs/docs/api/Cookies.md +122 -71
  24. package/node_modules/undici/docs/docs/api/Debug.md +34 -18
  25. package/node_modules/undici/docs/docs/api/DiagnosticsChannel.md +364 -164
  26. package/node_modules/undici/docs/docs/api/Dispatcher.md +485 -1102
  27. package/node_modules/undici/docs/docs/api/EnvHttpProxyAgent.md +101 -87
  28. package/node_modules/undici/docs/docs/api/Errors.md +503 -40
  29. package/node_modules/undici/docs/docs/api/EventSource.md +294 -32
  30. package/node_modules/undici/docs/docs/api/Fetch.md +680 -31
  31. package/node_modules/undici/docs/docs/api/GlobalInstallation.md +78 -98
  32. package/node_modules/undici/docs/docs/api/H2CClient.md +298 -176
  33. package/node_modules/undici/docs/docs/api/Interceptors.md +414 -0
  34. package/node_modules/undici/docs/docs/api/MockAgent.md +333 -314
  35. package/node_modules/undici/docs/docs/api/MockCallHistory.md +272 -98
  36. package/node_modules/undici/docs/docs/api/MockCallHistoryLog.md +189 -26
  37. package/node_modules/undici/docs/docs/api/MockClient.md +151 -33
  38. package/node_modules/undici/docs/docs/api/MockErrors.md +56 -5
  39. package/node_modules/undici/docs/docs/api/MockPool.md +321 -258
  40. package/node_modules/undici/docs/docs/api/Pool.md +235 -43
  41. package/node_modules/undici/docs/docs/api/PoolStats.md +119 -13
  42. package/node_modules/undici/docs/docs/api/ProxyAgent.md +179 -160
  43. package/node_modules/undici/docs/docs/api/RedirectHandler.md +238 -63
  44. package/node_modules/undici/docs/docs/api/RetryAgent.md +113 -26
  45. package/node_modules/undici/docs/docs/api/RetryHandler.md +161 -77
  46. package/node_modules/undici/docs/docs/api/RoundRobinPool.md +166 -72
  47. package/node_modules/undici/docs/docs/api/SnapshotAgent.md +264 -542
  48. package/node_modules/undici/docs/docs/api/Socks5ProxyAgent.md +162 -187
  49. package/node_modules/undici/docs/docs/api/Util.md +68 -11
  50. package/node_modules/undici/docs/docs/api/WebSocket.md +475 -80
  51. package/node_modules/undici/docs/docs/api/api-lifecycle.md +100 -32
  52. package/node_modules/undici/docs/docs/best-practices/client-certificate.md +2 -0
  53. package/node_modules/undici/docs/docs/best-practices/crawling.md +3 -1
  54. package/node_modules/undici/docs/docs/best-practices/migrating-from-v7-to-v8.md +6 -4
  55. package/node_modules/undici/docs/docs/best-practices/mocking-request.md +9 -7
  56. package/node_modules/undici/docs/docs/best-practices/proxy.md +3 -1
  57. package/node_modules/undici/docs/docs/best-practices/undici-vs-builtin-fetch.md +10 -8
  58. package/node_modules/undici/docs/docs/best-practices/writing-tests.md +2 -0
  59. package/node_modules/undici/docs/docs/{GettingStarted.md → getting-started.md} +22 -19
  60. package/node_modules/undici/docs/docs/index.md +784 -0
  61. package/node_modules/undici/docs/docs/site.json +125 -0
  62. package/node_modules/undici/docs/docs/type-map.json +79 -0
  63. package/node_modules/undici/lib/api/api-request.js +7 -1
  64. package/node_modules/undici/lib/api/readable.js +47 -2
  65. package/node_modules/undici/lib/cache/memory-cache-store.js +54 -9
  66. package/node_modules/undici/lib/cache/sqlite-cache-store.js +7 -1
  67. package/node_modules/undici/lib/core/errors.js +20 -0
  68. package/node_modules/undici/lib/core/request.js +14 -3
  69. package/node_modules/undici/lib/core/util.js +30 -2
  70. package/node_modules/undici/lib/dispatcher/agent.js +3 -3
  71. package/node_modules/undici/lib/dispatcher/client-h1.js +65 -8
  72. package/node_modules/undici/lib/dispatcher/client-h2.js +265 -142
  73. package/node_modules/undici/lib/dispatcher/proxy-agent.js +40 -6
  74. package/node_modules/undici/lib/global.js +36 -16
  75. package/node_modules/undici/lib/handler/cache-handler.js +269 -61
  76. package/node_modules/undici/lib/handler/cache-revalidation-handler.js +13 -3
  77. package/node_modules/undici/lib/handler/redirect-handler.js +6 -2
  78. package/node_modules/undici/lib/handler/retry-handler.js +87 -23
  79. package/node_modules/undici/lib/interceptor/cache.js +159 -52
  80. package/node_modules/undici/lib/interceptor/decompress.js +9 -2
  81. package/node_modules/undici/lib/mock/mock-interceptor.js +25 -7
  82. package/node_modules/undici/lib/mock/mock-utils.js +39 -10
  83. package/node_modules/undici/lib/util/cache.js +372 -68
  84. package/node_modules/undici/lib/util/date.js +23 -6
  85. package/node_modules/undici/lib/web/cookies/parse.js +3 -2
  86. package/node_modules/undici/lib/web/cookies/util.js +79 -9
  87. package/node_modules/undici/lib/web/eventsource/util.js +1 -1
  88. package/node_modules/undici/lib/web/fetch/body.js +2 -1
  89. package/node_modules/undici/lib/web/fetch/constants.js +1 -1
  90. package/node_modules/undici/lib/web/fetch/index.js +11 -2
  91. package/node_modules/undici/lib/web/fetch/response.js +1 -3
  92. package/node_modules/undici/lib/web/fetch/util.js +4 -1
  93. package/node_modules/undici/package.json +2 -2
  94. package/node_modules/undici/types/client.d.ts +3 -3
  95. package/node_modules/undici/types/cookies.d.ts +1 -1
  96. package/node_modules/undici/types/dispatcher.d.ts +3 -3
  97. package/node_modules/undici/types/errors.d.ts +10 -0
  98. package/node_modules/undici/types/handlers.d.ts +2 -0
  99. package/node_modules/undici/types/mock-interceptor.d.ts +5 -1
  100. package/node_modules/undici/types/proxy-agent.d.ts +7 -0
  101. package/npm-shrinkwrap.json +7 -7
  102. package/package.json +5 -5
  103. package/dist/provider.runtime-D1m66kDS.js +0 -2
@@ -1,275 +1,250 @@
1
- # Class: Socks5ProxyAgent
1
+ # Socks5ProxyAgent
2
2
 
3
- Extends: `undici.Dispatcher`
3
+ <!--introduced_in=v7.23.0-->
4
+ <!--type=module-->
5
+ <!-- source_link=lib/dispatcher/socks5-proxy-agent.js -->
4
6
 
5
- 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.
7
+ > Stability: 1 - Experimental
6
8
 
7
- ## `new Socks5ProxyAgent(proxyUrl[, options])`
9
+ A [`Dispatcher`][] implementation that routes requests through a [SOCKS5][]
10
+ proxy server. It tunnels both HTTP and HTTPS traffic over the proxy, supports
11
+ optional username/password authentication, and pools connections per origin so
12
+ that subsequent requests to the same host reuse the established tunnel.
8
13
 
9
- Arguments:
14
+ DNS resolution is delegated to the proxy: target host names are sent to the
15
+ proxy as domain names rather than being resolved locally. For HTTPS targets the
16
+ TLS session is negotiated end-to-end through the tunnel, so the proxy only sees
17
+ encrypted bytes.
10
18
 
11
- * **proxyUrl** `string | URL` (required) - The SOCKS5 proxy server URL. Must use `socks5://` or `socks://` protocol.
12
- * **options** `Socks5ProxyAgent.Options` (optional) - Additional configuration options.
19
+ Import it from `'undici'`:
13
20
 
14
- Returns: `Socks5ProxyAgent`
15
-
16
- ### Parameter: `Socks5ProxyAgent.Options`
17
-
18
- Extends: [`PoolOptions`](/docs/docs/api/Pool.md#parameter-pooloptions)
19
-
20
- * **headers** `IncomingHttpHeaders` (optional) - Additional headers to send with proxy connections.
21
- * **username** `string` (optional) - SOCKS5 proxy username for authentication. Can also be provided in the proxy URL.
22
- * **password** `string` (optional) - SOCKS5 proxy password for authentication. Can also be provided in the proxy URL.
23
- * **connect** `Function` (optional) - Custom connector function for the proxy connection.
24
- * **proxyTls** `BuildOptions` (optional) - TLS options for the proxy connection (when using SOCKS5 over TLS).
25
- * **requestTls** `BuildOptions` (optional) - TLS options applied to the HTTPS connection to the target server through the SOCKS5 tunnel. Use this to configure `ca`, `cert`, `key`, `rejectUnauthorized`, `servername`, etc. for the target HTTPS endpoint.
26
-
27
- Examples:
28
-
29
- ```js
21
+ ```mjs
30
22
  import { Socks5ProxyAgent } from 'undici'
31
-
32
- const socks5Proxy = new Socks5ProxyAgent('socks5://localhost:1080')
33
- // or with authentication
34
- const socks5ProxyWithAuth = new Socks5ProxyAgent('socks5://user:pass@localhost:1080')
35
- // or with options
36
- const socks5ProxyWithOptions = new Socks5ProxyAgent('socks5://localhost:1080', {
37
- username: 'user',
38
- password: 'pass',
39
- connections: 10
40
- })
41
23
  ```
42
24
 
43
- #### Example - Basic SOCKS5 Proxy instantiation
25
+ Constructing the agent emits a one-time `ExperimentalWarning`, reflecting the
26
+ experimental status of SOCKS5 support.
44
27
 
45
- This will instantiate the Socks5ProxyAgent. It will not do anything until registered as the dispatcher to use with requests.
28
+ ## Class: `Socks5ProxyAgent`
46
29
 
47
- ```js
48
- import { Socks5ProxyAgent } from 'undici'
30
+ <!-- YAML
31
+ added: v7.23.0
32
+ -->
49
33
 
50
- const socks5Proxy = new Socks5ProxyAgent('socks5://localhost:1080')
51
- ```
34
+ > Stability: 1 - Experimental
52
35
 
53
- #### Example - Basic SOCKS5 Proxy Request with global dispatcher
36
+ * Extends: {Dispatcher}
54
37
 
55
- ```js
56
- import { setGlobalDispatcher, request, Socks5ProxyAgent } from 'undici'
38
+ Routes dispatched requests through a SOCKS5 proxy. Register an instance as the
39
+ global dispatcher with [`setGlobalDispatcher()`][], or pass it per request via
40
+ the `dispatcher` option.
57
41
 
58
- const socks5Proxy = new Socks5ProxyAgent('socks5://localhost:1080')
59
- setGlobalDispatcher(socks5Proxy)
42
+ ### `new Socks5ProxyAgent(proxyUrl[, options])`
60
43
 
61
- const { statusCode, body } = await request('http://localhost:3000/foo')
44
+ <!-- YAML
45
+ added: v7.23.0
46
+ -->
62
47
 
63
- console.log('response received', statusCode) // response received 200
48
+ > Stability: 1 - Experimental
64
49
 
65
- for await (const data of body) {
66
- console.log('data', data.toString('utf8')) // data foo
67
- }
68
- ```
69
-
70
- #### Example - Basic SOCKS5 Proxy Request with local dispatcher
50
+ * `proxyUrl` {string|URL} The SOCKS5 proxy server URL. Must use the `socks5:` or
51
+ `socks:` protocol. Credentials may be embedded in the URL userinfo (for
52
+ example `socks5://user:pass@host:1080`).
53
+ * `options` {Object} (optional) Extends {PoolOptions}; the pool options are
54
+ applied to the per-origin pools created behind the tunnel.
55
+ * `headers` {Object} Additional headers to send with the proxy connection.
56
+ **Default:** `{}`.
57
+ * `username` {string} Username for SOCKS5 authentication. Takes precedence over
58
+ a username embedded in `proxyUrl`. **Default:** the URL username, if any.
59
+ * `password` {string} Password for SOCKS5 authentication. Takes precedence over
60
+ a password embedded in `proxyUrl`. **Default:** the URL password, if any.
61
+ * `connect` {Function} Custom connector used to open the socket to the proxy.
62
+ **Default:** a connector built from `proxyTls`.
63
+ * `proxyTls` {BuildOptions} TLS options for the connection to the proxy itself
64
+ (SOCKS5 over TLS). When set, the proxy connection is established over TLS and
65
+ `servername` defaults to the proxy host name.
66
+ * `requestTls` {BuildOptions} TLS options applied to the end-to-end connection
67
+ to an HTTPS target through the tunnel, such as `ca`, `cert`, `key`,
68
+ `rejectUnauthorized`, and `servername`. `servername` defaults to the target
69
+ host name.
71
70
 
72
- ```js
73
- import { Socks5ProxyAgent, request } from 'undici'
71
+ Throws an `InvalidArgumentError` if `proxyUrl` is missing or does not use the
72
+ `socks5:` or `socks:` protocol.
74
73
 
75
- const socks5Proxy = new Socks5ProxyAgent('socks5://localhost:1080')
74
+ ```mjs
75
+ import { Socks5ProxyAgent } from 'undici'
76
76
 
77
- const {
78
- statusCode,
79
- body
80
- } = await request('http://localhost:3000/foo', { dispatcher: socks5Proxy })
77
+ // Without authentication.
78
+ const agent = new Socks5ProxyAgent('socks5://localhost:1080')
81
79
 
82
- console.log('response received', statusCode) // response received 200
80
+ // With credentials in the URL.
81
+ const authAgent = new Socks5ProxyAgent('socks5://user:pass@localhost:1080')
83
82
 
84
- for await (const data of body) {
85
- console.log('data', data.toString('utf8')) // data foo
86
- }
83
+ // With credentials and pool options.
84
+ const configuredAgent = new Socks5ProxyAgent('socks5://localhost:1080', {
85
+ username: 'user',
86
+ password: 'pass',
87
+ connections: 10
88
+ })
87
89
  ```
88
90
 
89
- #### Example - SOCKS5 Proxy Request with authentication
91
+ Using the agent as the global dispatcher:
90
92
 
91
- ```js
93
+ ```mjs
92
94
  import { setGlobalDispatcher, request, Socks5ProxyAgent } from 'undici'
93
95
 
94
- // Authentication via URL
95
- const socks5Proxy = new Socks5ProxyAgent('socks5://username:password@localhost:1080')
96
-
97
- // Or authentication via options
98
- // const socks5Proxy = new Socks5ProxyAgent('socks5://localhost:1080', {
99
- // username: 'username',
100
- // password: 'password'
101
- // })
102
-
103
- setGlobalDispatcher(socks5Proxy)
96
+ const agent = new Socks5ProxyAgent('socks5://localhost:1080')
97
+ setGlobalDispatcher(agent)
104
98
 
105
99
  const { statusCode, body } = await request('http://localhost:3000/foo')
106
-
107
- console.log('response received', statusCode) // response received 200
100
+ console.log('response received', statusCode)
108
101
 
109
102
  for await (const data of body) {
110
- console.log('data', data.toString('utf8')) // data foo
103
+ console.log('data', data.toString('utf8'))
111
104
  }
112
105
  ```
113
106
 
114
- #### Example - SOCKS5 Proxy with HTTPS requests
115
-
116
- SOCKS5 proxy supports both HTTP and HTTPS requests through tunneling:
107
+ Using the agent per request:
117
108
 
118
- ```js
119
- import { Socks5ProxyAgent, request } from 'undici'
109
+ ```mjs
110
+ import { request, Socks5ProxyAgent } from 'undici'
120
111
 
121
- const socks5Proxy = new Socks5ProxyAgent('socks5://localhost:1080')
112
+ const agent = new Socks5ProxyAgent('socks5://localhost:1080')
122
113
 
123
- const response = await request('https://api.example.com/data', {
124
- dispatcher: socks5Proxy,
125
- method: 'GET'
114
+ const { statusCode, body } = await request('http://localhost:3000/foo', {
115
+ dispatcher: agent
126
116
  })
127
117
 
128
- console.log('Response status:', response.statusCode)
129
- console.log('Response data:', await response.body.json())
118
+ console.log('response received', statusCode)
130
119
  ```
131
120
 
132
- #### Example - SOCKS5 Proxy with Fetch
121
+ HTTPS targets are tunnelled and encrypted end-to-end:
133
122
 
134
- ```js
135
- import { Socks5ProxyAgent, fetch } from 'undici'
123
+ ```mjs
124
+ import { request, Socks5ProxyAgent } from 'undici'
136
125
 
137
- const socks5Proxy = new Socks5ProxyAgent('socks5://localhost:1080')
126
+ const agent = new Socks5ProxyAgent('socks5://localhost:1080')
138
127
 
139
- const response = await fetch('http://localhost:3000/api/users', {
140
- dispatcher: socks5Proxy,
141
- method: 'GET'
128
+ const { statusCode, body } = await request('https://api.example.com/data', {
129
+ dispatcher: agent
142
130
  })
143
131
 
144
- console.log('Response status:', response.status)
145
- console.log('Response data:', await response.text())
132
+ console.log('Response status:', statusCode)
133
+ console.log('Response data:', await body.json())
146
134
  ```
147
135
 
148
- #### Example - Connection Pooling
136
+ ### `socks5ProxyAgent.close()`
149
137
 
150
- SOCKS5ProxyWrapper automatically manages connection pooling for better performance:
138
+ <!-- YAML
139
+ added: v7.23.0
140
+ -->
151
141
 
152
- ```js
153
- import { Socks5ProxyAgent, request } from 'undici'
142
+ > Stability: 1 - Experimental
154
143
 
155
- const socks5Proxy = new Socks5ProxyAgent('socks5://localhost:1080', {
156
- connections: 10, // Allow up to 10 concurrent connections
157
- pipelining: 1 // Enable HTTP/1.1 pipelining
158
- })
144
+ * Returns: {Promise<void>} Resolves once every per-origin pool has been closed.
159
145
 
160
- // Multiple requests will reuse connections through the SOCKS5 tunnel
161
- const responses = await Promise.all([
162
- request('http://api.example.com/endpoint1', { dispatcher: socks5Proxy }),
163
- request('http://api.example.com/endpoint2', { dispatcher: socks5Proxy }),
164
- request('http://api.example.com/endpoint3', { dispatcher: socks5Proxy })
165
- ])
146
+ Gracefully closes the agent, waiting for all underlying pools and their
147
+ connections to drain and close before resolving.
166
148
 
167
- console.log('All requests completed through the same SOCKS5 proxy')
168
- ```
149
+ ```mjs
150
+ import { setGlobalDispatcher, Socks5ProxyAgent } from 'undici'
169
151
 
170
- ### `Socks5ProxyAgent.close()`
152
+ const agent = new Socks5ProxyAgent('socks5://localhost:1080')
153
+ setGlobalDispatcher(agent)
171
154
 
172
- Closes the SOCKS5 proxy wrapper and waits for all underlying pools and connections to close before resolving.
155
+ // ... make requests ...
173
156
 
174
- Returns: `Promise<void>`
175
-
176
- #### Example - clean up after tests are complete
177
-
178
- ```js
179
- import { Socks5ProxyAgent, setGlobalDispatcher } from 'undici'
180
-
181
- const socks5Proxy = new Socks5ProxyAgent('socks5://localhost:1080')
182
- setGlobalDispatcher(socks5Proxy)
183
-
184
- // ... make requests
185
-
186
- await socks5Proxy.close()
157
+ await agent.close()
187
158
  ```
188
159
 
189
- ### `Socks5ProxyAgent.destroy([err])`
160
+ ### `socks5ProxyAgent.destroy([err])`
190
161
 
191
- Destroys the SOCKS5 proxy wrapper and all underlying connections immediately.
162
+ <!-- YAML
163
+ added: v7.23.0
164
+ -->
192
165
 
193
- Arguments:
194
- * **err** `Error` (optional) - The error that caused the destruction.
166
+ > Stability: 1 - Experimental
195
167
 
196
- Returns: `Promise<void>`
168
+ * `err` {Error} (optional) The error to reject in-flight requests with.
169
+ * Returns: {Promise<void>} Resolves once every per-origin pool has been
170
+ destroyed.
197
171
 
198
- #### Example - force close all connections
172
+ Forcibly destroys the agent and all underlying connections immediately, without
173
+ waiting for in-flight requests to complete.
199
174
 
200
- ```js
175
+ ```mjs
201
176
  import { Socks5ProxyAgent } from 'undici'
202
177
 
203
- const socks5Proxy = new Socks5ProxyAgent('socks5://localhost:1080')
178
+ const agent = new Socks5ProxyAgent('socks5://localhost:1080')
204
179
 
205
- // Force close all connections
206
- await socks5Proxy.destroy()
180
+ await agent.destroy()
207
181
  ```
208
182
 
209
- ### `Socks5ProxyAgent.dispatch(options, handlers)`
210
-
211
- Implements [`Dispatcher.dispatch(options, handlers)`](/docs/docs/api/Dispatcher.md#dispatcherdispatchoptions-handlers).
183
+ ### `socks5ProxyAgent.dispatch(options, handlers)`
212
184
 
213
- ### `Socks5ProxyAgent.request(options[, callback])`
185
+ <!-- YAML
186
+ added: v7.23.0
187
+ -->
214
188
 
215
- See [`Dispatcher.request(options [, callback])`](/docs/docs/api/Dispatcher.md#dispatcherrequestoptions-callback).
189
+ > Stability: 1 - Experimental
216
190
 
217
- ## Debugging
218
-
219
- SOCKS5 proxy connections can be debugged using Node.js diagnostics:
220
-
221
- ```sh
222
- NODE_DEBUG=undici:socks5 node script.js
223
- ```
191
+ * `options` {DispatchOptions}
192
+ * `handlers` {DispatchHandler}
193
+ * Returns: {boolean} `false` if the dispatcher is busy and the request should be
194
+ retried later, otherwise `true`.
224
195
 
225
- This will output detailed information about the SOCKS5 handshake, authentication, and connection establishment.
196
+ Routes a request through the SOCKS5 tunnel. The agent maintains a [`Pool`][] per
197
+ target origin; the first request to a given origin establishes the tunnel and
198
+ upgrades to TLS when the target is HTTPS, and later requests reuse the pool.
226
199
 
227
- ## SOCKS5 Protocol Support
200
+ This is the lower-level entry point implementing
201
+ [`Dispatcher.dispatch(options, handlers)`][]. Prefer
202
+ [`socks5ProxyAgent.request()`][] for most use cases.
228
203
 
229
- The Socks5ProxyAgent supports the following SOCKS5 features:
204
+ ### `socks5ProxyAgent.request(options[, callback])`
230
205
 
231
- ### Authentication Methods
206
+ <!-- YAML
207
+ added: v7.23.0
208
+ -->
232
209
 
233
- - **No Authentication** (`0x00`) - For public or internal proxies
234
- - **Username/Password** (`0x02`) - RFC 1929 authentication
210
+ > Stability: 1 - Experimental
235
211
 
236
- ### Address Types
212
+ * `options` {DispatchOptions}
213
+ * `callback` {Function} (optional)
214
+ * Returns: {Promise|void} A promise resolving to the response when `callback` is
215
+ omitted.
237
216
 
238
- - **IPv4** (`0x01`) - Standard IPv4 addresses
239
- - **Domain Name** (`0x03`) - Domain names (recommended for flexibility)
240
- - **IPv6** (`0x04`) - IPv6 addresses (full support for standard and compressed notation)
217
+ Performs a request through the SOCKS5 proxy. Inherited from
218
+ [`Dispatcher.request(options[, callback])`][]; see that method for the full set
219
+ of options and the shape of the resolved response.
241
220
 
242
- ### Commands
221
+ ```mjs
222
+ import { fetch, Socks5ProxyAgent } from 'undici'
243
223
 
244
- - **CONNECT** (`0x01`) - Establish TCP connection (primary use case for HTTP)
224
+ const agent = new Socks5ProxyAgent('socks5://localhost:1080')
245
225
 
246
- ### Error Handling
247
-
248
- The wrapper handles various SOCKS5 error conditions:
249
-
250
- - Connection refused by proxy
251
- - Authentication failures
252
- - Network unreachable
253
- - Host unreachable
254
- - Unsupported address types or commands
226
+ const response = await fetch('http://localhost:3000/api/users', {
227
+ dispatcher: agent
228
+ })
255
229
 
256
- ## Performance Considerations
230
+ console.log('Response status:', response.status)
231
+ console.log('Response data:', await response.text())
232
+ ```
257
233
 
258
- - **Connection Pooling**: Automatically pools connections through the SOCKS5 tunnel for better performance
259
- - **HTTP/1.1 Pipelining**: Supports pipelining when enabled
260
- - **DNS Resolution**: Domain names are resolved by the SOCKS5 proxy, reducing local DNS queries
261
- - **TLS Termination**: HTTPS connections are encrypted end-to-end, with the SOCKS5 proxy only handling the TCP tunnel
234
+ ## Debugging
262
235
 
263
- ## Security Notes
236
+ SOCKS5 proxy activity can be traced with the `undici:socks5-proxy` debug scope:
264
237
 
265
- 1. **Authentication**: Credentials are sent to the SOCKS5 proxy in plaintext unless using SOCKS5 over TLS
266
- 2. **DNS Leaks**: All DNS resolution happens on the proxy server, preventing DNS leaks
267
- 3. **End-to-end Encryption**: HTTPS traffic remains encrypted between client and final destination
268
- 4. **Connection Security**: Consider using authenticated proxies and secure networks
238
+ ```bash
239
+ NODE_DEBUG=undici:socks5-proxy node script.js
240
+ ```
269
241
 
270
- ## Compatibility
242
+ This logs the SOCKS5 handshake, authentication, and tunnel establishment steps.
271
243
 
272
- - **Protocol**: SOCKS5 (RFC 1928) with Username/Password Authentication (RFC 1929)
273
- - **Transport**: TCP only (UDP support not implemented)
274
- - **Node.js**: Compatible with all supported Node.js versions
275
- - **HTTP Versions**: Works with HTTP/1.1 and HTTP/2 over the tunnel
244
+ [SOCKS5]: https://www.rfc-editor.org/rfc/rfc1928
245
+ [`Dispatcher.dispatch(options, handlers)`]: Dispatcher.md#dispatcherdispatchoptions-handler
246
+ [`Dispatcher.request(options[, callback])`]: Dispatcher.md#dispatcherrequestoptions-callback
247
+ [`Dispatcher`]: Dispatcher.md#class-dispatcher
248
+ [`Pool`]: Pool.md#class-pool
249
+ [`setGlobalDispatcher()`]: Dispatcher.md#setglobaldispatcherdispatcher
250
+ [`socks5ProxyAgent.request()`]: #socks5proxyagentrequestoptions-callback
@@ -1,25 +1,82 @@
1
1
  # Util
2
2
 
3
- Utility API for third-party implementations of the dispatcher API.
3
+ <!--introduced_in=v1.2.0-->
4
+ <!--type=module-->
5
+ <!-- source_link=lib/core/util.js -->
4
6
 
5
- ## `parseHeaders(headers, [obj])`
7
+ > Stability: 2 - Stable
6
8
 
7
- Receives a header object and returns the parsed value.
9
+ A small set of utility helpers exposed for third-party implementations of the
10
+ [`Dispatcher`][] API. They cover the header-handling primitives undici uses
11
+ internally, so that custom dispatchers and handlers can normalize header names
12
+ and parse raw header lists exactly the way undici does.
8
13
 
9
- Arguments:
14
+ ```mjs
15
+ import { util } from 'undici'
10
16
 
11
- - **headers** `(Buffer | string | (Buffer | string)[])[]` (required) - Header object.
17
+ const { parseHeaders, headerNameToString } = util
18
+ ```
12
19
 
13
- - **obj** `Record<string, string | string[]>` (optional) - Object to specify a proxy object. The parsed value is assigned to this object. But, if **headers** is an object, it is not used.
20
+ ```cjs
21
+ const { util } = require('undici')
14
22
 
15
- Returns: `Record<string, string | string[]>` If **obj** is specified, it is equivalent to **obj**.
23
+ const { parseHeaders, headerNameToString } = util
24
+ ```
25
+
26
+ ## `parseHeaders(headers[, obj])`
27
+
28
+ <!-- YAML
29
+ added: v1.2.0
30
+ changes:
31
+ - version: v6.1.0
32
+ pr-url: https://github.com/nodejs/undici/pull/2501
33
+ description: Header names supplied as a `Buffer` are accepted and normalized.
34
+ -->
35
+
36
+ * `headers` {Array} A flat list of raw header entries where even indices are
37
+ header names and odd indices are the corresponding values. Each entry is a
38
+ {string}, {Buffer}, or an array of {string}/{Buffer}.
39
+ * `obj` {Record<string, string|string[]>} An object to assign the parsed values
40
+ to. When omitted, a new object is created. **Default:** `{}`.
41
+ * Returns: {Record<string, string|string[]>} The object the parsed headers were
42
+ assigned to. When `obj` is provided, the same reference is returned.
43
+
44
+ Receives a flat list of raw header name/value pairs and returns them as an
45
+ object keyed by lowercased header name. Header names are normalized with
46
+ [`headerNameToString()`][], and `Buffer` values are decoded as `latin1`. When a
47
+ header name appears more than once, its values are collected into an array.
48
+
49
+ ```mjs
50
+ import { util } from 'undici'
51
+
52
+ const raw = ['Content-Type', 'text/plain', 'Set-Cookie', 'a=1', 'Set-Cookie', 'b=2']
53
+
54
+ console.log(util.parseHeaders(raw))
55
+ // { 'content-type': 'text/plain', 'set-cookie': [ 'a=1', 'b=2' ] }
56
+ ```
16
57
 
17
58
  ## `headerNameToString(value)`
18
59
 
19
- Retrieves a header name and returns its lowercase value.
60
+ <!-- YAML
61
+ added: v6.1.0
62
+ -->
63
+
64
+ * `value` {string|Buffer} The header name to normalize.
65
+ * Returns: {string} The lowercased header name.
66
+
67
+ Returns the lowercased form of a header name. The `value` may be provided as a
68
+ {string} or as a {Buffer}, in which case it is decoded as `latin1`. Common
69
+ header names are resolved through an internal lookup table for performance.
70
+
71
+ ```mjs
72
+ import { util } from 'undici'
20
73
 
21
- Arguments:
74
+ console.log(util.headerNameToString('Content-Type'))
75
+ // 'content-type'
22
76
 
23
- - **value** `string | Buffer` (required) - Header name.
77
+ console.log(util.headerNameToString(Buffer.from('X-Custom-Header')))
78
+ // 'x-custom-header'
79
+ ```
24
80
 
25
- Returns: `string`
81
+ [`Dispatcher`]: Dispatcher.md#class-dispatcher
82
+ [`headerNameToString()`]: #headernametostringvalue