http-party / node-http-proxy

A full-featured http proxy for node.js
https://github.com/http-party/node-http-proxy
Other
13.89k stars 1.97k forks source link

Forward proxy with filtering #786

Open ranode opened 9 years ago

ranode commented 9 years ago

Hello! I would like to create a forward proxy that can filter our requests to certain restricted domains, but forward all other requests to the corresponding url in the internet and send the response back to the client - something like a web filter. Is this possible with this module? Couldn't find an example on the examples folder to do this. Is there any detailed documentation?

valaxy commented 9 years ago

+1 I'm also confused about this, in my opinion, "node-http-proxy" is aiming at reverse proxy, but we are looking for a forward proxy module

chbdetta commented 9 years ago

+1

n-samir commented 8 years ago

I feel the same... all examples in node-http-proxy refer to hard-wired target URLs giving an indication that it is targeted as a reverse proxy. I did not see a single example anywhere of its use as a forward proxy. And when I tried, had all kinds of problems.

Illizian commented 8 years ago

Hi, a little late to the party but I am currently achieving this with the following code:

var server = http.createServer(function(req, res) {
  if (!! isFiltered(req)) {
    // Respond with FILTERED page
    return renderFiltered(res);
  }

  return proxy.web(req, res, {
    target: req.url,
    ignorePath: true,
    xfwd: true
  });
});

function renderFiltered(res) {
  res.writeHead(403, { 'Content-Type': 'text/html' });
  res.write(filteredHtml);
  res.end();
}

Unfortunately I am seeing some strange issues where CDNs are sending me 404s for certain files yet the requests from the proxy are identical to those coming from the browser - it's very odd.

* UPDATE: * I resolved the 404s, it appears some wierdness within the path config was causing a duplication of the path so domain.com/path was becoming domain.com/path/path adding the ignorePath config prevents this.