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

Already on GitHub? Sign in to your account

Straight proxy gives server errors on some hosts #516

Open
shermozle opened this Issue Nov 12, 2013 · 3 comments

Comments

Projects
None yet
2 participants

As instructed by @jcrugzz I tried this against the caronte branch. Same code, same result.

Using the proxy as a straight HTTP proxy works fine for most URLs but I find I'm getting 400 Bad Request from one particular server.

This pattern of using the proxy, a standard client proxy, isn't that easy to work out from the examples. I don't want to proxy an internal server, I want to proxy requests going to outbound servers, look at the requests and either log them or potentially change them on the way through. Though I'm not doing any of this in the test stub below.

Is there something I'm doing wrong with the proxy setup? It's strange that it works everywhere else except this one server.

Test stub I'm using:

var httpProxy = require('/home/simon/node_modules/http-proxy'),
        url = require('url');

httpProxy.createServer(function (req, res, proxy) {
    var parsedUrl = url.parse(req.url);

    console.log(req.url);

    proxy.proxyRequest(req, res, {
        host: parsedUrl.hostname,
        port: parsedUrl.port ? port: 80
    });
}).listen(9000);

Using curl I get a 500 server error:

curl -x localhost:9000 -v 'http://bigpondmusic.com' >/dev/null
* About to connect() to proxy localhost port 9000 (#0)
*   Trying 127.0.0.1...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* connected
* Connected to localhost (127.0.0.1) port 9000 (#0)
> GET http://bigpondmusic.com HTTP/1.1
> User-Agent: curl/7.27.0
> Host: bigpondmusic.com
> Accept: */*
> Proxy-Connection: Keep-Alive
> 
* additional stuff not fine transfer.c:1037: 0 0
* HTTP 1.1 or later with persistent connection, pipelining supported
< HTTP/1.1 500 Internal Server Error
< content-length: 88
< content-type: text/html
< server: Microsoft-IIS/6.0
< date: Tue, 12 Nov 2013 01:35:12 GMT
< connection: close
< 
  0    88    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0{ [data not shown]
100    88  100    88    0     0    334      0 --:--:-- --:--:-- --:--:--   334
* Closing connection #0

Oddly, with Firefox I get a 400 Bad Request error:

Request URL:    http://bigpondmusic.com/
Request Method:     GET
Status Code:    HTTP/1.1 400 Bad Request
Request Headers 12:33:49.000
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:25.0) Gecko/20100101 Firefox/25.0
Host:   bigpondmusic.com
Connection: keep-alive
Accept-Language:    en-US,en;q=0.5
Accept-Encoding:    gzip, deflate
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Response Headers Δ245ms
x-powered-by:   ASP.NET
Transfer-Encoding:  chunked
Server: Microsoft-IIS/6.0
Date:   Tue, 12 Nov 2013 01:33:49 GMT
Content-Type:   text/html; charset=utf-8
Connection: close
Owner

jcrugzz commented Nov 12, 2013

@shermozle you must be using the wrong branch or not the right code. You can install it with npm install "git://github.com/nodejitsu/node-http-proxy#caronte". The api is not the same so the code you have posted will not work. See the new readme

Okay done that. Now trying to make some sense of the examples. I don't see
how I can specify the destination server depending on the request. i.e.,
how to create a standard HTTP proxy, not an application reverse proxy.

On 13 November 2013 09:55, Jarrett Cruger notifications@github.com wrote:

@shermozle https://github.com/shermozle you must be using the wrong
branch or not the right code. You can install it with npm install "git://
github.com/nodejitsu/node-http-proxy#caronte". The api is not the same so
the code you have posted will not work. See the new readmehttps://github.com/nodejitsu/node-http-proxy/tree/caronte#core-concept


Reply to this email directly or view it on GitHubhttps://github.com/nodejitsu/node-http-proxy/issues/516#issuecomment-28342350
.

Simon Rumble simon@simonrumble.com
www.simonrumble.com

Owner

jcrugzz commented Jan 22, 2014

@shermozle sorry for the late response. Check out the ProxyTable API example in our blog post. Let me know if you have anymore questions!

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