MCPcopy Create free account
hub / github.com/nodejs/node / handleHandshakeResponse

Method handleHandshakeResponse

deps/undici/src/lib/core/socks5-client.js:182–209  ·  view source on GitHub ↗

* Handle handshake response from server

()

Source from the content-addressed store, hash-verified

180 * Handle handshake response from server
181 */
182 handleHandshakeResponse () {
183 if (this.buffer.length < 2) {
184 return // Not enough data yet
185 }
186
187 const version = this.buffer[0]
188 const method = this.buffer[1]
189
190 if (version !== SOCKS_VERSION) {
191 throw new Socks5ProxyError(`Invalid SOCKS version: ${version}`, 'UND_ERR_SOCKS5_VERSION')
192 }
193
194 if (method === AUTH_METHODS.NO_ACCEPTABLE) {
195 throw new Socks5ProxyError('No acceptable authentication method', 'UND_ERR_SOCKS5_AUTH_REJECTED')
196 }
197
198 this.buffer = this.buffer.subarray(2)
199 debug('server selected auth method', method)
200
201 if (method === AUTH_METHODS.NO_AUTH) {
202 this.markAuthenticated()
203 } else if (method === AUTH_METHODS.USERNAME_PASSWORD) {
204 this.state = STATES.AUTHENTICATING
205 this.sendAuthRequest()
206 } else {
207 throw new Socks5ProxyError(`Unsupported authentication method: ${method}`, 'UND_ERR_SOCKS5_AUTH_METHOD')
208 }
209 }
210
211 /**
212 * Send username/password authentication request

Callers 1

onDataMethod · 0.95

Calls 3

markAuthenticatedMethod · 0.95
sendAuthRequestMethod · 0.95
debugFunction · 0.50

Tested by

no test coverage detected