1

I am trying to create a node-http-proxy server that explicitly sets the Date passed in all requests. Can anyone please advise me how to do this.

i.e. I want to force the date passed in all HTTP request(s) to be a date in the past

Setting the Date in the req.headers does not appear to work:

var http = require('http'),
    httpProxy = require('http-proxy');

var proxy = httpProxy.createProxyServer({});
var server = http.createServer(function(req, res) {

  console.log("Proxying: " + req.url);
  req.headers["Date"] = "Fri, 18 Dec 2015 08:49:37 GMT";
  //req.headers["date"] = "Fri, 18 Dec 2015 08:49:37 GMT";
  proxy.web(req, res, { target: 'http://somewhereElse.com:9090' });
});

console.log("listening on port 8888")
server.listen(8888);
Mark J
  • 11
  • 2

1 Answers1

1

Look at this link.

So in your case:

var http = require('http'),
    httpProxy = require('http-proxy');

//
// Create a proxy server with custom application logic
//
var proxy = httpProxy.createProxyServer({});

// To modify the proxy connection before data is sent, you can listen
// for the 'proxyReq' event. When the event is fired, you will receive
// the following arguments:
// (http.ClientRequest proxyReq, http.IncomingMessage req,
//  http.ServerResponse res, Object options). This mechanism is useful when
// you need to modify the proxy request before the proxy connection
// is made to the target.
//
proxy.on('proxyReq', function(proxyReq, req, res, options) {
  proxyReq.setHeader('Date', 'Fri, 18 Dec 2015 08:49:37 GMT');
});

var server = http.createServer(function(req, res) {
  // You can define here your custom logic to handle the request
  // and then proxy the request.
  proxy.web(req, res, {
    target: 'http://127.0.0.1:9090'
  });
});

console.log("listening on port 8888")
server.listen(8888);
oleh.meleshko
  • 4,675
  • 2
  • 27
  • 40
  • This solution does not work for me. The site I am targetting is still using the current Date. Whereas if I change the system DateTime on my browser machine then the site uses this Date. NOTE: My target host is not 127.0.0.1 as in the example code above but a URL on a separate host. Hence I am assuming that it must be getting the Date from the HTTP request somehow. – Mark J Mar 16 '16 at 12:36
  • I have figured my issue out: 1) The Date information was being passed in an application specific GET parameter and not via a Date: header 2) "Date:" headers are part of the HTTP response and not the HTTP Request as I had originally thought. – Mark J Mar 17 '16 at 16:31