Permalink
Browse files

Work in progress

  • Loading branch information...
1 parent 7613d36 commit b70f8a60c1d0cb2851530f4975c719c85841b4bd @s3u committed Dec 22, 2010
Showing with 38 additions and 21 deletions.
  1. +3 −3 lib/client-proxy.js
  2. +35 −18 sandbox/www-client/www-client.js
View
@@ -9,7 +9,7 @@ var handler = function (req, res) {
if (!host) {
return badRequest(res, 'Missing Host header')
}
-/*
+
var proxyAuthorization = req.headers['Proxy-Authorization']
if (!proxyAuthorization) {
return unauthorized(res)
@@ -26,9 +26,9 @@ var handler = function (req, res) {
proxyTheRequest(req, res)
}
else {
- unathorized(res)
+ unauthorized(res)
}
- */
+
proxyTheRequest(req, res)
}
@@ -5,7 +5,7 @@ var connect = require('connect'),
http = require('http'),
client = require('../../lib/client'),
querystring = require('querystring'),
- nstore = require('nstore');
+ nstore = require('nstore')
//
// This needs to be launched via proxychains
@@ -15,9 +15,9 @@ function manageClients(app) {
app.resource('/try', {
// Provide a UI for registering the client
get: function(req, res) {
- res.render('try.ejs');
+ res.render('try.ejs')
}
- });
+ })
app.resource('/getsomedata', {
@@ -30,29 +30,46 @@ function manageClients(app) {
method: 'GET',
uri: 'http://localhost:5000/resource',
proxy: 'http://localhost:3030',
+ headers: {
+ 'Authorization' : req.headers.authorization
+ },
clientError: function(clientRes) {
- sys.log("ERROR");
+ sys.log("ERROR")
+ res.end()
},
success: function(clientRes) {
- sys.log("SUCCESS");
- var data = '';
+ sys.log("SUCCESS")
+ var data = ''
clientRes.on('data', function(chunk) {
- data += chunk;
- });
+ data += chunk
+ })
clientRes.on('end', function() {
- data = JSON.parse(data);
- res.render('gotsomedata.ejs', data);
- res.end();
+ data = JSON.parse(data)
+ res.render('gotsomedata.ejs', data)
+ res.end()
})
}
- });
+ })
}
- });
+ })
+}
+
+var users = {
+ 'user0' : 'password',
+ 'user1' : 'password',
+ 'user2' : 'password'
}
-var server = express.createServer();
-server.use(express.bodyDecoder());
-server.use(resource(manageClients));
-server.listen(4000);
-console.log('Client running on port 4000');
+
+
+var server = express.createServer()
+
+// todo: use basic auth for now. switch to forms later.
+server.use(connect.basicAuth(function(user, password){
+ return users[user] && users[user].password == password
+}))
+server.use(express.bodyDecoder())
+server.use(resource(manageClients))
+server.listen(4000)
+console.log('Client running on port 4000')

0 comments on commit b70f8a6

Please sign in to comment.