Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/dispatcher/socks5-proxy-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class Socks5ProxyAgent extends DispatcherBase {
/**
* Dispatch a request through the SOCKS5 proxy
*/
async [kDispatch] (opts, handler) {
[kDispatch] (opts, handler) {
const { origin } = opts

debug('dispatching request to', origin, 'via SOCKS5')
Expand Down Expand Up @@ -230,8 +230,12 @@ class Socks5ProxyAgent extends DispatcherBase {
return pool[kDispatch](opts, handler)
} catch (err) {
debug('dispatch error:', err)
if (typeof handler.onError === 'function') {
if (typeof handler.onResponseError === 'function') {
handler.onResponseError(null, err)
return false
} else if (typeof handler.onError === 'function') {
handler.onError(err)
return false
} else {
throw err
}
Expand Down
22 changes: 22 additions & 0 deletions test/socks5-proxy-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,28 @@ test('Socks5ProxyAgent - uses custom connector for proxy connection', async (t)
await p.completed
})

test('Socks5ProxyAgent - dispatch returns boolean backpressure signal', async (t) => {
const p = tspl(t, { plan: 1 })
const proxyWrapper = new Socks5ProxyAgent('socks5://localhost:9999')

const ret = proxyWrapper.dispatch({
origin: 'http://example.com',
path: '/',
method: 'GET'
}, {
onRequestStart () {},
onResponseStart () {},
onResponseData () {},
onResponseEnd () {},
onResponseError () {}
})

p.equal(typeof ret, 'boolean')

await proxyWrapper.destroy()
await p.completed
})

test('Socks5ProxyAgent - basic HTTP connection', async (t) => {
const p = tspl(t, { plan: 2 })

Expand Down
Loading