You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2013/03/21 00:55:53 UTC
git commit: Includes /upload_basic_auth (POST) and
/download_basic_auth (GET) endpoints that need basic auth credentials
Updated Branches:
refs/heads/cordova-filetransfer 008b90a7e -> 7b34db531
Includes /upload_basic_auth (POST) and /download_basic_auth (GET) endpoints that need basic auth credentials
"cordova_user:cordova_password". If the credentials are not ok, it returns HTTP 401.
Project: http://git-wip-us.apache.org/repos/asf/cordova-labs/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-labs/commit/7b34db53
Tree: http://git-wip-us.apache.org/repos/asf/cordova-labs/tree/7b34db53
Diff: http://git-wip-us.apache.org/repos/asf/cordova-labs/diff/7b34db53
Branch: refs/heads/cordova-filetransfer
Commit: 7b34db53173849ae293dc169efc15fedb55147de
Parents: 008b90a
Author: Shazron Abdullah <sh...@apache.org>
Authored: Wed Mar 20 16:55:44 2013 -0700
Committer: Shazron Abdullah <sh...@apache.org>
Committed: Wed Mar 20 16:55:44 2013 -0700
----------------------------------------------------------------------
server.js | 39 +++++++++++++++++++++++++++++++++++++--
1 files changed, 37 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-labs/blob/7b34db53/server.js
----------------------------------------------------------------------
diff --git a/server.js b/server.js
index 9e581c3..1eb2958 100644
--- a/server.js
+++ b/server.js
@@ -4,8 +4,27 @@ var formidable = require('formidable'),
port = process.env.PORT || 5000;
http.createServer(function (req, res) {
+
+ var basic_auth_username = "cordova_user";
+ var basic_auth_password = "cordova_password";
+
+ var header = req.headers['authorization']||'', // get the header
+ token = header.split(/\s+/).pop()||'', // and the encoded auth token
+ auth = new Buffer(token, 'base64').toString(), // convert from base64
+ parts = auth.split(/:/), // split on colon
+ username = parts[0],
+ password = parts[1];
- if (req.url === "/robots.txt") {
+ if (req.url === "/download_basic_auth") {
+ if (username != basic_auth_username && password != basic_auth_password) {
+ res.writeHead(401, {'Content-Type': 'text/plain'});
+ res.end("401\n");
+ } else {
+ res.writeHead(200, {'Content-Type': 'text/plain'});
+ res.write("User-Agent: *\n");
+ res.end("Disallow: /\n");
+ }
+ } else if (req.url === "/robots.txt") {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write("User-Agent: *\n");
res.end("Disallow: /\n");
@@ -23,6 +42,22 @@ http.createServer(function (req, res) {
console.log
res.end("\n");
});
+ } else if (req.url == '/upload_basic_auth' && req.method.toLowerCase() == 'post') {
+ if (username != basic_auth_username && password != basic_auth_password) {
+ res.writeHead(401, {'Content-Type': 'text/plain'});
+ res.end("401\n");
+ } else {
+ var form = new formidable.IncomingForm();
+ form.parse(req, function(err, fields, files) {
+ res.writeHead(200, {'content-type': 'text/plain'});
+ console.log(util.inspect({fields: fields, files: files}));
+
+ res.write('received upload:\n\n');
+ res.write(util.inspect({fields: fields, files: files}));
+ console.log
+ res.end("\n");
+ });
+ }
} else if (req.url.match(/\d{3}/)) {
var matches = req.url.match(/\d{3}/);
status = matches[0];
@@ -36,4 +71,4 @@ http.createServer(function (req, res) {
console.log(req.connection.remoteAddress + " " + req.method + " " + req.url + " " + res.statusCode + " " + req.headers['user-agent']);
}).listen(port, '0.0.0.0');
-console.log('Server running on ' + port);
+console.log('Server running on ' + port);
\ No newline at end of file