nodejitsu/node-http-proxy — Issue #185: Inconsistent behavior with proxyError depending on createServer invocation
Author: n1mmy
Created: 2012-02-01 00:39:00+00:00
State: open

How the proxy behaves when a proxyError occurs seems to depend in odd ways on how the server was invoked.

When created like this (first example in README):

```javascript
var httpProxy = require('http-proxy');
var server = httpProxy.createServer(24, 'localhost');
server.listen(8000);
```

The proxy returns 500 with a message that the connection was refused.

However, if you start the proxy like this (second example in the README):

```javascript
var httpProxy = require('http-proxy');
var server = httpProxy.createServer(function (req, res, proxy) {
proxy.proxyRequest(req, res, {
host: '127.0.0.1', port: 24
});
});
server.listen(8000);
```
The proxied connections simply hang forever (until client timeout).

Adding custom error handling code works in both cases:

```javascript
server.proxy.on('proxyError', function (err, req, res) {
res.writeHead(500, {
'Content-Type': 'text/plain'
});
res.end('Something went wrong. And we are reporting a custom error message.');
console.log("XXX", err);
});
```

This is especially confusing since the README does not mention proxyError at all.