koichik/node-tunnel

https requerst parameter mismatch throws uncaught Exception

Closed this issue · 1 comments

using global-tunnel to connect behind a proxy
when using https (bypassing options to http) throws following Exception

ps actual request was made by the twitter js sdk

Exception has occurred: TypeError
TypeError: Request path contains unescaped characters
    at new ClientRequest (_http_client.js:52:11)
    at TunnelingAgent.exports.request (http.js:31:10)
    at TunnelingAgent.createSocket (/Users/d062254/Documents/sap git/srch-middleware/node_modules/tunnel/lib/tunnel.js:124:25)
    at TunnelingAgent.createSecureSocket [as createSocket] (/Users/d062254/Documents/sap git/srch-middleware/node_modules/tunnel/lib/tunnel.js:196:41)
    at TunnelingAgent.addRequest (/Users/d062254/Documents/sap git/srch-middleware/node_modules/tunnel/lib/tunnel.js:88:8)
    at new ClientRequest (_http_client.js:159:16)
    at Object.exports.request (http.js:31:10)
    at Object.globalTunnel._defaultedAgentRequest (/Users/d062254/Documents/sap git/srch-middleware/node_modules/global-tunnel/index.js:211:38)
    at Object.exports.request (https.js:199:15)
    at Object.globalTunnel._defaultedAgentRequest (/Users/d062254/Documents/sap git/srch-middleware/node_modules/global-tunnel/index.js:211:38)

i fixed the issueby adding the following in /lib/tunnel.js

//... line 69 ...
TunnelingAgent.prototype.addRequest = function addRequest(req, host, port) {
  var self = this;
  var options;
  if (typeof host === 'object')
  {
    options = host;
    host = options.host;
    port = options.port;
  }
// end bugfix
  if (self.sockets.length >= this.maxSockets) {
    // We are over limit so we'll add it to the queue.
    self.requests.push({host: host, port: port, request: req});
    return;
  }

usage of globalTunnel

import * as globalTunnel from "global-tunnel";
globalTunnel.initialize({
    tunnel: 'both',
    protocol: 'http:',
    host: 'proxy.sam.corp',
    port: 8080,
    sockets: 50 // optional pool size for each http and https
  });

actual request is being created by twitter-node-client

import * as TwitterLib from "twitter-node-client";

var twitterClient = new TwitterLib.Twitter({
    consumerKey : "bla",
    consumerSecret : "shh",
    accessToken : "wa",
    accessTokenSecret : "shshsh"
});

twitterClient.getSearch({'q': term, 'count': 10, 'result\_type':'popular'},
    (err:Error)=> { reject(err); },
    (tweets) => { resolve(tweets); });

Thanks for the report.
global-tunnel uses tunnel@0.0.2, but it doesn't support node v0.12 or later.