Skip to content

proxy to specific url failed #184

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
terrywh opened this issue Jan 31, 2012 · 6 comments
Closed

proxy to specific url failed #184

terrywh opened this issue Jan 31, 2012 · 6 comments

Comments

@terrywh
Copy link

terrywh commented Jan 31, 2012

I try to proxy a request to
http://ptlogin2.qq.com/jump?ptlang=2052&clientuin=304290615&clientkey=0D399336F7C4F553C468779FC21FEC92B77EEE1F3D766C61BC3F3B19AD65E070&u1=http%3A%2F%2Fuser.qzone.qq.com%2F573692919
which actually send a "302 Found" status code, but the proxy failed to send any response which cause Chrome showing an "ERR_EMPTY_RESPONSE" error page.

i found visit that url cause proxyError, and i add some code found it to be "error: { [Error: socket hang up] code: 'ECONNRESET' }"

and i get the similar error when proxy to url http://stats.sports.qq.com/NBAImages/TeamImages/Bulls-1.png

my source code:

var http = require('http'),
    httpProxy = require('http-proxy'),
    url  = require('url');
//
// Create your proxy server
//
httpProxy.createServer(function (req, res, proxy) {
  //
  // Buffer the request so that `data` and `end` events
  // are not lost during async operation(s).
  //
  var buffer = httpProxy.buffer(req);
  var parsed_url = url.parse(req.url);
  var host = "localhost";
  var port = 8001;
  if(typeof(parsed_url.host)=='undefined') {
  } else {
      port = parsed_url.host.split(':');
      host = parsed_url.hostname;
      if(port[1]) {
        port = port[1];
      }else{
        port = 80;
      }
  }
  //setTimeout(function () {
    proxy.proxyRequest(req, res, {
       'host': host,
       'port': port,
       'buffer': buffer,
    });      
  //}, 2000);
}).listen(8000);
@AvianFlu
Copy link
Contributor

The server you're trying to proxy to might be expecting certain headers that aren't being passed through - or it might be rejecting requests that have obviously been proxied.

node-http-proxy sets the x-forwarded-* headers, and your connections may be getting refused because of this.

@coderarity
Copy link
Contributor

@wuhaocn2008 are you still having an issue with this?

@terrywh
Copy link
Author

terrywh commented Mar 30, 2012

it seems the latter url is ok right now, but the first url is still having some kind of issue when i use the proxy server on CHROME to visit. It keeps loading for a very long time.

@coderarity
Copy link
Contributor

I think the problem is the query part of the URL. I'm going to work on getting rid of the hanging problems in node-http-proxy, I think that's the source of a lot of people's problems. Clear error messages are far more useful than hanging.

@coderarity
Copy link
Contributor

It sounds like it was hanging - I just added a pull request to give reasonable errors instead of just hanging. See #216. After that pull request is merged in and a new version is up on npm, can you try it again and tell me what error it gives you (if any)?

@terrywh
Copy link
Author

terrywh commented Apr 10, 2012

USE proxyError to track the errors, here is what i got when proxy the first url:

{ [Error: socket hang up] code: 'ECONNRESET' }

it seems you are right about the x-forwarded-for thing. when i proxy some url, it will emit that reset error. For the specific url on top, the reason might be that there should not be a header "x-forwarded" or the server will close the connection.

Thank you for all your trouble.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants