Permalink
Browse files

basic auth configuration via command line

  • Loading branch information...
1 parent 5791d28 commit ee5948b40aed1bbc0778d9d5908a49b0ce79b638 @igrigorik committed Jun 22, 2012
Showing with 32 additions and 28 deletions.
  1. +3 −3 bin/spdyproxy
  2. +29 −25 lib/server.js
View
@@ -31,12 +31,12 @@ var path = require('path')
},
user: {
demand: false,
- alias: 'u',
- description: 'basich auth username'
+ alias: 'U',
+ description: 'basic auth username'
},
pass: {
demand: false,
- alias: 'p',
+ alias: 'P',
description: 'basic auth password'
}
}).argv;
View
@@ -76,33 +76,37 @@ var SPDYProxy = function(options) {
function handleRequest(req, res) {
logRequest(req);
- // perform basic proxy auth (over SSL tunnel)
- // - http://www.chromium.org/spdy/spdy-authentication
- var header = req.headers['proxy-authorization'] || '',
- token = header.split(/\s+/).pop() || '',
- auth = new Buffer(token, 'base64').toString(),
- parts = auth.split(/:/),
- username = parts[0],
- password = parts[1];
-
- // don't pass proxy-auth headers upstream
- delete req.headers['proxy-authorization'];
-
- // TODO add config
- if(username != 'test') {
- var socket = (req.method == 'CONNECT') ? res : res.socket;
- synReply(socket, 407, 'Proxy Authentication Required',
- {'Proxy-Authenticate': 'Basic realm="SPDY Proxy"'},
- function() { socket.end(); }
- );
-
- } else {
- if (req.method == 'CONNECT') {
- handleSecure(req, res);
- } else {
- handlePlain(req, res);
+ if (options.user) {
+ // perform basic proxy auth (over established SSL tunnel)
+ // - http://www.chromium.org/spdy/spdy-authentication
+ var header = req.headers['proxy-authorization'] || '',
+ token = header.split(/\s+/).pop() || '',
+ auth = new Buffer(token, 'base64').toString(),
+ parts = auth.split(/:/),
+ username = parts[0],
+ password = parts[1];
+
+ // don't pass proxy-auth headers upstream
+ 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() {
+ socket.end();
+ }
+ );
+
+ return;
}
}
+
+ if (req.method == 'CONNECT') {
+ handleSecure(req, res);
+ } else {
+ handlePlain(req, res);
+ }
}
spdy.server.Server.call(this, options);

0 comments on commit ee5948b

Please sign in to comment.