Skip to content

Using different hostnames with request.js seems to be broken #17

@philiiiiiipp

Description

@philiiiiiipp

Hey, I tried to use the Agent in combination with request and changing tor proxy hostnames. One Tor is running on localhost, the other on 'tor_proxy'.

request(
        {
          uri: 'http://ipv4bot.whatismyipaddress.com',
          agentClass: Agent,
          agentOptions: {
            socksHost: 'localhost',
            socksPort: Tor.PORT
          }
        }, function (error, response, body) {
        console.log(body);
});

works as expected, the request is running over the localhost tor. The second request however

request(
        {
          uri: 'http://ipv4bot.whatismyipaddress.com',
          agentClass: Agent,
          agentOptions: {
            socksHost: 'tor_proxy',
            socksPort: Tor.PORT
          }
        }, function (error, response, body) {
        console.log(body);
});

Is also running over localhost. I investigated a bit further, and looking at which options are coming into socks5-http-client/lib/Agent, the first one is

Url {
  protocol: 'http:',
  slashes: true,
  auth: null,
  host: 'ipv4bot.whatismyipaddress.com',
  port: 80,
  hostname: 'ipv4bot.whatismyipaddress.com',
  hash: null,
  search: null,
  query: null,
  pathname: '/',
  path: '/',
  href: 'http://ipv4bot.whatismyipaddress.com/',
  socksPort: 9050,
  socksHost: 'localhost' }

and the second one

Url {
  protocol: 'http:',
  slashes: true,
  auth: null,
  host: 'ipv4bot.whatismyipaddress.com',
  port: 80,
  hostname: 'ipv4bot.whatismyipaddress.com',
  hash: null,
  search: null,
  query: null,
  pathname: '/',
  path: '/',
  href: 'http://ipv4bot.whatismyipaddress.com/',
  socksPort: 9050,
  socksHost: 'tor_proxy',
  agent: 
   Agent {
     domain: null,
     _events: { free: [Function] },
     _eventsCount: 1,
     _maxListeners: undefined,
     defaultPort: 80,
     protocol: 'http:',
     options: 
      { socksHost: 'localhost',
        socksPort: 9050,
        href: 'http://ipv4bot.whatismyipaddress.com/',
        path: null,
        pathname: '/',
        query: null,
        search: null,
        hash: null,
        hostname: 'ipv4bot.whatismyipaddress.com',
        port: 80,
        host: 'ipv4bot.whatismyipaddress.com',
        auth: null,
        slashes: true,
        protocol: 'http:' },
     requests: {},
     sockets: {},
     freeSockets: {},
     keepAliveMsecs: 1000,
     keepAlive: false,
     maxSockets: Infinity,
     maxFreeSockets: 256,
     socksHost: 'localhost',
     socksPort: 9050,
     createConnection: [Function] } `}

Seems like request is caching the agent if it used one before and so not changing the proxy hostname.

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