Skip to content

Unable to proxy DNS requests when using a proxy-agent #344

@sheldhur

Description

@sheldhur

#324

I have the same problem when I use proxy-agent. In this package socks5h works like socks5

import url from 'url';
import https from 'https';
import { ProxyAgent } from 'proxy-agent';
import { SocksProxyAgent } from 'socks-proxy-agent';

const proxy = 'socks5h://127.0.0.1:9050';
const endpoint = 'https://duckduckgogg42xjoc72x3sjasowoarfbgcmvfimaftt6twagswzczad.onion';

function sendHttpRequest(endpoint, agent) {
  const options = url.parse(endpoint);
  options.agent = agent;

  const outgoing = https.get(options);

  return new Promise((resolve, reject) => {
    outgoing.on('response', (res) => resolve(res));
    outgoing.on('error', (err) => reject(err));
  });
}

(async () => {
  try {
    const res = await sendHttpRequest(endpoint, new SocksProxyAgent(proxy));
    console.log('onion via socks-proxy-agent', res.statusCode);
  } catch (err) {
    console.error('onion via socks-proxy-agent', err);
  }


  try {
    const res = await sendHttpRequest(endpoint, new ProxyAgent(proxy));
    console.log('onion via proxy-agent', res.statusCode);
  } catch (err) {
    console.error('onion via proxy-agent', err);
  }
})();
onion via socks-proxy-agent 200
onion via proxy-agent Error: getaddrinfo ENOTFOUND duckduckgogg42xjoc72x3sjasowoarfbgcmvfimaftt6twagswzczad.onion
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:109:26) {
  errno: -3008,
  code: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: 'duckduckgogg42xjoc72x3sjasowoarfbgcmvfimaftt6twagswzczad.onion'
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions