Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
philiiiiiipp opened this issue Apr 15, 2016 · 2 comments
Open

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

philiiiiiipp opened this issue Apr 15, 2016 · 2 comments

Comments

@philiiiiiipp
Copy link

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.

@abdulqadir93
Copy link

I had a similar problem. I was having trouble changing the ports in consecutive requests. I solved it by passing a new instance of Agent class to the agent property instead of passing agentClass and agentOptions separately.

const Agent = require('socks5-http-client/lib/Agent');
const request = require('request');

request({
    url: 'http://whatismyipaddress.com',
    agent: new Agent({
         socksHost: 'localhost',
         socksPort: 9050
    })
}, (err, res, body) => {
    // do something with the response
})

Hope this helps!

@shiny
Copy link

shiny commented Jun 30, 2016

got the same problem

daijie pushed a commit to daijie/proxy-filter that referenced this issue Jun 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants