Permalink
Browse files

add verbose logging flag, improve output

  • Loading branch information...
1 parent ee5948b commit 172db6774e75e6c576b082a9b053f9e2f538b37a @igrigorik committed Jun 22, 2012
Showing with 27 additions and 9 deletions.
  1. +13 −3 bin/spdyproxy
  2. +12 −5 lib/server.js
  3. +2 −1 package.json
View
@@ -3,10 +3,11 @@
var path = require('path')
, pkg = require('../package.json')
, version = pkg.version
+ , colors = require('colors')
, spdyProxy = require('../lib/server')
, fs = require('fs')
, opts = require('optimist')
- .usage('Usage: $0 -x - y')
+ .usage('Usage: $0')
.options({
key: {
demand: true,
@@ -38,6 +39,12 @@ var path = require('path')
demand: false,
alias: 'P',
description: 'basic auth password'
+ },
+ verbose: {
+ demand: false,
+ alias: 'v',
+ description: 'enable verbose logging',
+ default: false
}
}).argv;
@@ -46,10 +53,13 @@ opts.cert = fs.readFileSync(path.resolve(opts.cert));
opts.ca = fs.readFileSync(path.resolve(opts.ca));
process.on('uncaughtException', function(e) {
- console.error('Error: ' + e);
+ console.error('Error: '.red + e);
});
var proxy = new spdyProxy.createServer(opts);
proxy.listen(opts.port);
-console.log("started server");
+console.log(
+ "Started SPDY proxy, port: ".green + opts.port
+ + (" (v. %s)").grey, version
+);
View
@@ -7,9 +7,10 @@ var spdy = require('spdy'),
var SPDYProxy = function(options) {
function logRequest(req) {
- console.log(req.method + ' ' + req.url);
+ console.log(req.method.green + ' ' + req.url.yellow);
for (var i in req.headers)
- console.log(' * ' + i + ': ' + req.headers[i]);
+ console.log(' > '.grey + i.cyan + ': ' + req.headers[i]);
+ console.log();
}
function synReply(socket, code, reason, headers, cb) {
@@ -66,15 +67,22 @@ var SPDYProxy = function(options) {
tunnel.setNoDelay(true);
tunnel.on('error', function(e) {
- console.log("Tunnel error: " + e);
+ console.log("Tunnel error: ".red + e);
synReply(socket, 502, "Tunnel Error", {}, function() {
socket.end();
});
});
}
function handleRequest(req, res) {
- logRequest(req);
+ if (options.verbose) logRequest(req);
+
+ var socket = (req.method == 'CONNECT') ? res : res.socket;
+ console.log("%s:%s".yellow + " - %s - " + "stream ID: " + "%s".yellow,
+ socket.connection.socket.remoteAddress,
+ socket.connection.socket.remotePort,
+ req.method, res.streamID || socket.streamID
+ );
if (options.user) {
// perform basic proxy auth (over established SSL tunnel)
@@ -90,7 +98,6 @@ var SPDYProxy = function(options) {
delete req.headers['proxy-authorization'];
if((username != options.user) || (password != options.pass)) {
- var socket = (req.method == 'CONNECT') ? res : res.socket;
synReply(socket, 407, 'Proxy Authentication Required',
{'Proxy-Authenticate': 'Basic realm="SPDY Proxy"'},
function() {
View
@@ -13,7 +13,8 @@
"dependencies": {
"spdy": "1.2.1",
- "optimist": "*"
+ "optimist": "*",
+ "colors": "*"
},
"main": "./lib/server.js",

0 comments on commit 172db67

Please sign in to comment.