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

Problem with http-https redirection behind proxy: Error: tunneling socket could not be established, cause=Parse Error #1357

Closed
rkrejcii opened this issue Jan 15, 2015 · 7 comments
Labels

Comments

@rkrejcii
Copy link

Hi.

I have problem using following code (GET request via authorised proxy) in the case of redirection from HTTP to HTTPS site. When I for example request
http://twitter.com
I'm getting error message
{ [Error: tunneling socket could not be established, cause=Parse Error] code: 'ECONNRESET' }

Redirection is taken in account as the followRedirect callback returns following response.headers:

{ 'content-length': '0',
  date: 'Thu, 15 Jan 2015 15:01:14 UTC',
  location: 'https://twitter.com/',
  server: 'tsa_b',
  'set-cookie': [ 'guest_id=v1%3A142133407487424756; Domain=.twitter.com; Path=/; Expires=Sat, 14-Jan-2017 15:01:14 UTC' ],
  'x-connection-hash': 'fd168ae941d6db2cef7c0ddc48826e57',
  'x-response-time': '2' }

The problematic code (sensitive info hidden):

var request = require('request');

var agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A";

var proxyPort = "XXX";
var proxyLogin = "XXX";
var proxyPwd = "XXX";

var proxyIP = "XXX.XXX.XXX.XXX";

var proxyURL = 'http://' + proxyIP + ":" + proxyPort;
var auth = 'Basic ' + new Buffer(proxyLogin + ':' + proxyPwd).toString('base64');

var url = "http://twitter.com/";

request({
        method: 'get',
        url: url,
        proxy: proxyURL,
        timeout: 10000,
        tunnel: true,
        sendImmediately: true,
        followAllRedirects: true,
        followRedirect: function(response){console.log(response.headers); return true;},
        headers: {
            'User-Agent': agent,
            "Cache-Control" : "no-cache",
                'Proxy-Authorization': auth,
        }
    }, function(err, response, body){
        if (err) {
            console.log(err);
        } else {
            console.log(response.statusCode);
        }
    }
)

Thanks for every help.

@nylen
Copy link
Member

nylen commented Jan 25, 2015

so, you're getting a redirect to https://twitter.com/, what happens if you make that your URL instead of http: ?

also, a standalone test case that reproduces the problem would be really helpful. see test-tunnel.js for examples of how to do this.

@Freyert
Copy link

Freyert commented Dec 1, 2015

Getting this same error as well. My question is where can we find this error message in the request library?

Found it: https://github.com/mikeal/tunnel-agent/blob/master/index.js#L174

@Freyert
Copy link

Freyert commented Dec 2, 2015

@rkrejcii figure out what was causing mine. It's an error when it tries to parse the headers in my case. I'm using cradle and it sets Content-Length instead of not caring, or letting request handle it, or using content-length instead. When I remove the header it works great.

Thoughts now are, perhaps I need to whitelist Content-Length. Perhaps only whitelisted headers are parsed.

@Freyert
Copy link

Freyert commented Dec 2, 2015

Well, content-length is already on the whitelist.

@simov
Copy link
Member

simov commented Dec 4, 2015

The content-length header was removed from the whitelist here #1915 though this fix is not published yet. The whitelist contains headers that are allowed to be sent to the proxy server.

@jachstet-sea
Copy link

On what operating systems are you all on? Could you please check if my comments in npm/npm#3084 (comment) are usefule to you?

@stale
Copy link

stale bot commented Nov 23, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Nov 23, 2018
@stale stale bot closed this as completed Dec 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants