Question regarding changing url with proxyRequest #435

Closed
fostahgix opened this Issue Jun 21, 2013 · 2 comments

Projects

None yet

2 participants

@fostahgix

More of a question than an issue..

The Issue: When manually changing the req.headers.host to a remote host ('example.com'(and some other custom logic)), 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!

Example: myproxy.com:8004/?url=example.com -> would change url in the browser to example.com.

The code I am using to do this currently:
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
// and some other custom logic before proxying...
var buffer = httpProxy.buffer(req);
setTimeout(function () {
proxy.proxyRequest(req, res, {
port: 80,
host: 'example.com',
buffer: buffer
});
}, 200);
}).listen(8004);

Any help is greatly appreciated!

@mmalecki

You're not looking for a proxy at all. You're looking for a way to redirect requests.

var http = require('http');

http.createServer(function (req, res) {
  res.writeHead(301, { 'location': 'example.com' });
  res.end();
}).listen(8004);
@mmalecki mmalecki closed this Jun 23, 2013
@fostahgix

Thanks for the followup. The requirement was to evaluate the clients IP and user-agent evaluate` on some logic, either pass the request through to its original endpoint, or change the endpoint to a splash page.

So the flow on our system would be.
-User connects to our system.
-User navigates to example.com
-That request(and all port 80 requests) is redirected to our proxy via iptables (ie. proxyserver:8004/?url=http://example.com)
-The proxy determines if the request should continue to example.com or be redirected to splashpageexample.com.

So if we just do a 301, I think we will get into an endless loop of redirects. Is there anyway to just change the endpoint of the request while changing url in the browser so it is transparent to the user that their request being evaluated before being passed through? Thanks for any advice on this!

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