Skip to content

toProxy option is broken #703

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

Closed
samcday opened this issue Sep 23, 2014 · 7 comments
Closed

toProxy option is broken #703

samcday opened this issue Sep 23, 2014 · 7 comments

Comments

@samcday
Copy link

samcday commented Sep 23, 2014

In the first place it's somewhat poorly documented, so perhaps I'm just doing it wrong.

Say I do this:

  req.url = "http://destination/yay";

  proxy.web(req, res, {
    target: "http://mysquidproxy:3128",
    toProxy: true
  });

I should expect squidproxy:3128 to receive a GET http://destination/yay HTTP/1.1. Instead, it receives a GET http:/destination/yay HTTP/1.1 - note the single slash after protocol. It looks like common.urlJoin is causing the munging here.

@jcrugzz
Copy link
Contributor

jcrugzz commented Sep 23, 2014

@samcday could you submit this in the form of a broken test case? It must be too simplistic. It may be fixed by url-join if you want to submit a fix with that broken test case. Otherwise I'll give it a look later today

@samcday
Copy link
Author

samcday commented Sep 25, 2014

@jcrugzz not sure I'll have time to look into this further. I think the information I set out in the original issue description is enough to reliably reproduce the problem.

I ended up just rolling my own proxying using mikeal/request, since it handles client proxying pretty elegantly, and I didn't really need any of the other bells-and-whistles from http-proxy.

@odmarkj
Copy link

odmarkj commented Oct 9, 2014

Just an FYI, this was the problem line for me: outgoing.path = common.urlJoin(targetPath, outgoingPath); in common.js.

This was returning an invalid URL.

targetPath = '/';
outgoingPath = 'http://joshuaodmark.com/proxy_test.php';

Was returning "/http:/joshuaodmark.com/proxy_test.php".

@yulesyu
Copy link

yulesyu commented Nov 4, 2014

rewrite function common.urlJoin as follow:

common.urlJoin = function() {
var args = Array.prototype.slice.call(arguments);
// Join all strings, but remove empty strings so we don't get extra slashes from
// joining e.g. ['', 'am']
var arr = args.filter(function filter(a) {
return !!a;
});

var i = 0;
for(i = 0; i < arr.length; i++)
{
arr[i] = arr[i].replace(/([\s\S]?)(/)$/, function(all, sec1, sec2){
return sec1;
});
}

arr = arr.filter(function(a){
return !!a;
});

return arr.join('/');
};

@jcrugzz
Copy link
Contributor

jcrugzz commented Nov 4, 2014

@yulesyu will take a pull request with added test!

@jcrugzz
Copy link
Contributor

jcrugzz commented Dec 2, 2014

Should be fixed

@jcrugzz jcrugzz closed this as completed Dec 2, 2014
@callmemagnus
Copy link

I'm using 1.11.2 and trying to make my request hit a cntlm proxy.

I see the requests but the url is like:

cntlm[32283]: 127.0.0.1 GET /https://<host>/<path>

Note the slash at the beginning of the URL.

I'm using the toProxy=true option, putting the proxy as my target and changing the req.url to contain the host part.

If I disable it, the url becomes only the <path>.

Is this a regression ? Or am I badly miss-using the module ?

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

5 participants