1

When modifying a node-http-proxy example...

The Issue: When manually changing the req.headers.host to a remote host ('example.com'), the url in the the browser is not changing.

Note: I thought this was working, however when using google.com as my example, it turned out google was detecting the proxy and changing the host.

Question: Is there a way to change the url in the browser to a remote host (ie. example.com), everytime? Thanks!

var util = require('util'),
    colors = require('colors'),
    http = require('http'),
    httpProxy = require('../../lib/node-http-proxy');

//
// Http Server with proxyRequest Handler and Latency
//
var proxy = new httpProxy.RoutingProxy();
http.createServer(function (req, res) {
  req.headers.host = 'example.com'; // manually setting example.com
  var buffer = httpProxy.buffer(req);
  setTimeout(function () {
    proxy.proxyRequest(req, res, {
      port: 80,
      host: 'example.com',
      buffer: buffer
    });
  }, 200);
}).listen(8004);



util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '8004 '.yellow + 'with proxyRequest handler'.cyan.underline + ' and latency'.magenta);
util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9000 '.yellow);

1 Answer 1

0

A few solutions that will do this are:

  • Issue a 301 redirect.
  • Use IPTables to DNAT and change the desination address.
  • Use TPROXY to transparently proxy the requests without modifying the packets.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.