Skip to content

Commit 84470b3

Browse files
mcollinaclaude
andcommitted
refactor: address second round of PR review feedback
- Remove unnecessary `async` from `handshake()` and `connect()` - Remove commented-out `reserved` variable in `handleConnectResponse()` - Add NODE_DEBUG documentation to Socks5ProxyAgent.md Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Matteo Collina <hello@matteocollina.com>
1 parent 9426fae commit 84470b3

3 files changed

Lines changed: 13 additions & 6 deletions

File tree

docs/docs/api/Socks5ProxyAgent.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,16 @@ Implements [`Dispatcher.dispatch(options, handlers)`](/docs/docs/api/Dispatcher.
213213

214214
See [`Dispatcher.request(options [, callback])`](/docs/docs/api/Dispatcher.md#dispatcherrequestoptions-callback).
215215

216+
## Debugging
217+
218+
SOCKS5 proxy connections can be debugged using Node.js diagnostics:
219+
220+
```sh
221+
NODE_DEBUG=undici:socks5 node script.js
222+
```
223+
224+
This will output detailed information about the SOCKS5 handshake, authentication, and connection establishment.
225+
216226
## SOCKS5 Protocol Support
217227

218228
The Socks5ProxyAgent supports the following SOCKS5 features:

lib/core/socks5-client.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class Socks5Client extends EventEmitter {
142142
/**
143143
* Start the SOCKS5 handshake
144144
*/
145-
async handshake () {
145+
handshake () {
146146
if (this.state !== STATES.INITIAL) {
147147
throw new InvalidArgumentError('Handshake already started')
148148
}
@@ -262,7 +262,7 @@ class Socks5Client extends EventEmitter {
262262
* @param {string} address - Target address (IP or domain)
263263
* @param {number} port - Target port
264264
*/
265-
async connect (address, port) {
265+
connect (address, port) {
266266
if (this.state === STATES.CONNECTED) {
267267
throw new InvalidArgumentError('Already connected')
268268
}
@@ -308,7 +308,6 @@ class Socks5Client extends EventEmitter {
308308

309309
const version = this.buffer[0]
310310
const reply = this.buffer[1]
311-
// const reserved = this.buffer[2] // Not used
312311
const addressType = this.buffer[3]
313312

314313
if (version !== SOCKS_VERSION) {

test/socks5-client.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,7 @@ test('Socks5Client - connection refused', async (t) => {
307307
const client = new Socks5Client(socket)
308308

309309
client.on('authenticated', () => {
310-
client.connect('example.com', 80).catch(() => {
311-
// Error is handled in the error event
312-
})
310+
client.connect('example.com', 80)
313311
})
314312

315313
client.on('error', (err) => {

0 commit comments

Comments
 (0)