adding x-forward headers

This commit is contained in:
Chris Cowan 2015-01-26 11:52:07 -07:00
parent 598a1b4419
commit 51ca59a4f3

View file

@ -35,6 +35,12 @@ router.use(function (req, res, next) {
req.on('end', next);
});
function getPort(req) {
var matches = req.headers.host.match(/:(\d+)/);
if (matches[1]) return matches[1];
return req.connection.pair ? '443' : '80';
}
// Create the proxy middleware
router.use(function (req, res, next) {
@ -47,6 +53,11 @@ router.use(function (req, res, next) {
timeout: config.kibana.request_timeout
};
options.headers['x-forward-for'] = req.connection.remoteAddress || req.socket.remoteAddress;
options.headers['x-forward-port'] = getPort(req);
options.headers['x-forward-proto'] = req.connection.pair ? 'https' : 'http';
// If the server has a custom CA we need to add it to the agent options
if (hasCustomCA) {
options.agentOptions = { ca: https.globalAgent.options.ca };