Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

More enhancements and bump version

  • Loading branch information...
commit ee4b1901f367ecd6963a5f0e44a3794b6516a2c6 1 parent 27aaaab
@creationix authored
Showing with 22 additions and 6 deletions.
  1. +14 −4 auth.js
  2. +1 −1  package.json
  3. +7 −1 static.js
View
18 auth.js
@@ -1,9 +1,19 @@
/*global Buffer*/
-var Crypto = require('crypto');
+var Crypto = require('crypto'),
+ Url = require('url');
-module.exports = function setup(secrets) {
+module.exports = function setup(match, secrets) {
return function handle(req, res, next) {
- if (req.headers.authorization) {
+ if (!req.hasOwnProperty("uri")) { req.uri = Url.parse(req.url); }
+ if (!match.test(req.uri.pathname)) {
+ return next();
+ }
+ if (req.client.remoteAddress !== '127.0.0.1') {
+ res.writeHead(302, {"Location": "https://" + req.headers.host + req.url});
+ res.end();
+ return;
+ }
+ if (req.client.remoteAddress === '127.0.0.1' && req.headers.authorization) {
var parts = req.headers.authorization.split(' ');
parts = (new Buffer(parts[1], 'base64')).toString('utf8').split(':');
var username = parts[0];
@@ -14,7 +24,7 @@ module.exports = function setup(secrets) {
}
}
res.writeHead(401, {
- "WWW-Authenticate": "Basic realm=" + secrets.realm,
+ "WWW-Authenticate": 'Basic realm="Secure Area"',
"Content-Type": "text/plain"
});
res.end("Authorization Required");
View
2  package.json
@@ -2,7 +2,7 @@
"name": "creationix",
"description": "Creationix is a meta package for my personal packages",
"tags": ["stack", "creationix", "meta", "sandbox"],
- "version": "0.0.4",
+ "version": "0.0.5",
"author": "Tim Caswell <tim@creationix.com>",
"repository": {
"type": "git",
View
8 static.js
@@ -71,8 +71,14 @@ module.exports = function setup(mount, root, index) {
}
headers["Content-Length"] = end - start + 1;
headers["Content-Type"] = getMime(path);
+ if (stat.size === 0) {
+ res.writeHead(code, headers);
+ return res.end();
+ }
var stream = Fs.createReadStream(path, {start: start, end: end});
- res.writeHead(code, headers);
+ stream.once('data', function (chunk) {
+ res.writeHead(code, headers);
+ });
stream.pipe(res);
stream.on('error', next);
}
Please sign in to comment.
Something went wrong with that request. Please try again.