Skip to content

Commit

Permalink
Add support for via.
Browse files Browse the repository at this point in the history
  • Loading branch information
axiak committed Feb 4, 2012
1 parent fd4cea1 commit c3a6b7c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/proxy.js
Expand Up @@ -4,6 +4,7 @@ var http = require('http')
, https = require('https')
, net = require('net')
, path = require('path')
, exec = require('exec')
, EventEmitter = require('events').EventEmitter;

if (!RegExp.escape) {
Expand All @@ -12,10 +13,23 @@ if (!RegExp.escape) {
};
}

var serverHostName = 'unknown';

exec("hostname", function (err, stdout, stderr) {
serverHostName = stdout.trim();
});

module.exports.createProxyServer = function (opts) {
opts = opts || {};
var main_port = ~~(opts['port'] || process.env.PORT || 8128);
var hostname = opts['hostname'];
var via;

if (opts['via'] === undefined) {
via = 'nodeproxy/0.0.1';
} else if (opts['via'] !== false) {
via = opts['via'];
}

var emitter = new EventEmitter();

Expand Down Expand Up @@ -58,6 +72,10 @@ module.exports.createProxyServer = function (opts) {
}
headers['forwarded-for'] = headers['x-forwarded-for'];

if (via) {
headers['via'] = request.httpVersion + ' ' + serverHostName + ':' + request.connection.address().port + ' (' + via + ')';
}

var request_info = {
'host': parsed_url.hostname || parsed_host.hostname,
'port': ~~(parsed_url.port || parsed_host.port || (is_ssl ? 443 : 80)),
Expand Down

0 comments on commit c3a6b7c

Please sign in to comment.