Permalink
Browse files

get everything in

  • Loading branch information...
1 parent 613987b commit 4d62409a2deb8721c5fec235a28a76ddb3335aa3 @zzo committed Nov 9, 2011
Showing 2,165 changed files with 52,419 additions and 871,287 deletions.
@@ -6,7 +6,7 @@
<body class="yui3-skin-sam">
<div id="log" />
<script src="http://yui.yahooapis.com/3.3.0/build/yui/yui-min.js"></script>
- <script src="toolbar.js?coverage=1"></script>
+ <script src="toolbar.js?coverage=1"></script>
<script src="testToolbar.js"></script>
</body>
</html>
@@ -26,7 +26,7 @@ exports = module.exports = createServer;
* Framework version.
*/
-exports.version = '1.6.0';
+exports.version = '1.7.2';
/**
* Initialize a new `connect.HTTPServer` with the middleware
@@ -145,11 +145,11 @@ Server.prototype.handle = function(req, res, out) {
layer = stack[index++];
// all done
- if (!layer) {
+ if (!layer || res.headerSent) {
// but wait! we have a parent
if (out) return out(err);
- // otherwise send a proper error message to the browser.
+ // error
if (err) {
var msg = 'production' == env
? 'Internal Server Error'
@@ -158,6 +158,9 @@ Server.prototype.handle = function(req, res, out) {
// output to stderr in a non-test env
if ('test' != env) console.error(err.stack || err.toString());
+ // unable to respond
+ if (res.headerSent) return req.socket.destroy();
+
res.statusCode = 500;
res.setHeader('Content-Type', 'text/plain');
res.end(msg);
@@ -28,6 +28,7 @@
* - [methodOverride](middleware-methodOverride.html) faux HTTP method support
* - [responseTime](middleware-responseTime.html) calculates response-time and exposes via X-Response-Time
* - [router](middleware-router.html) provides rich Sinatra / Express-like routing
+ * - [staticCache](middleware-staticCache.html) memory cache layer for the static() middleware
* - [static](middleware-static.html) streaming static file server supporting `Range` and more
* - [directory](middleware-directory.html) directory listing middleware
* - [vhost](middleware-vhost.html) virtual host sub-domain mapping middleware
@@ -31,7 +31,7 @@ var cache = {};
*
* Compilers:
*
- * - `sass` Compiles cass to css
+ * - `sass` Compiles sass to css
* - `less` Compiles less to css
* - `coffeescript` Compiles coffee to js
*
@@ -22,8 +22,8 @@ var utils = require('../utils')
* property which is re-generated per request.
*
* The default `value` function checks `req.body` generated
- * by the `bodyParser()` middleware, and `req.query` generated
- * by `query()`.
+ * by the `bodyParser()` middleware, `req.query` generated
+ * by `query()`, and the "X-CSRF-Token" header field.
*
* This middleware requires session support, thus should be added
* somewhere _below_ `session()` and `cookieParser()`.
@@ -74,8 +74,7 @@ module.exports = function csrf(options) {
return function(req, res, next){
// generate CSRF token
- var token = req.session._csrf;
- req.session._csrf = utils.uid(24);
+ var token = req.session._csrf || (req.session._csrf = utils.uid(24));
// ignore GET (for now)
if ('GET' == req.method) return next();
@@ -101,5 +100,6 @@ module.exports = function csrf(options) {
function defaultValue(req) {
return (req.body && req.body._csrf)
- || (req.query && req.query._csrf);
+ || (req.query && req.query._csrf)
+ || (req.headers['x-csrf-token']);
}
@@ -62,6 +62,9 @@ exports = module.exports = function directory(root, options){
, originalDir = decodeURIComponent(originalUrl.pathname)
, showUp = path != root && path != root + '/';
+ // null byte(s)
+ if (~path.indexOf('\0')) return utils.badRequest(res);
+
// malicious path
if (0 != path.indexOf(root)) return utils.forbidden(res);
@@ -78,6 +81,7 @@ exports = module.exports = function directory(root, options){
if (err) return next(err);
if (!hidden) files = removeHidden(files);
if (filter) files = files.filter(filter);
+ files.sort();
// content-negotiation
for (var key in exports) {
if (~accept.indexOf(key) || ~accept.indexOf('*/*')) {
@@ -43,7 +43,11 @@ module.exports = function limit(bytes){
req._limit = true;
// limit by content-length
- if (len && len > bytes) deny();
+ if (len && len > bytes) {
+ res.statusCode = 413;
+ res.end('Request Entity Too Large');
+ return;
+ }
// limit
req.on('data', function(chunk){
@@ -26,6 +26,7 @@ var defaultBufferDuration = 1000;
* - `format` Format string, see below for tokens
* - `stream` Output stream, defaults to _stdout_
* - `buffer` Buffer duration, defaults to 1000ms when _true_
+ * - `immediate` Write log line on request instead of response (for response times)
*
* Tokens:
*
@@ -88,6 +89,9 @@ exports = module.exports = function logger(options) {
options = {};
}
+ // output on request instead of response
+ var immediate = options.immediate;
+
// format name
var fmt = exports[options.format] || options.format || exports.default;
@@ -130,13 +134,23 @@ exports = module.exports = function logger(options) {
// flag as logging
req._logging = true;
- // proxy end to output loggging
- var end = res.end;
- res.end = function(chunk, encoding){
- res.end = end;
- res.end(chunk, encoding);
- stream.write(fmt(exports, req, res) + '\n', 'ascii');
- };
+ // immediate
+ if (immediate) {
+ var line = fmt(exports, req, res);
+ if (null == line) return;
+ stream.write(line + '\n', 'ascii');
+ } else {
+ // proxy end to output loggging
+ var end = res.end;
+ res.end = function(chunk, encoding){
+ res.end = end;
+ res.end(chunk, encoding);
+ var line = fmt(exports, req, res);
+ if (null == line) return;
+ stream.write(line + '\n', 'ascii');
+ };
+ }
+
next();
};
@@ -55,10 +55,10 @@ function defaultFingerprint(req) {
};
/**
- * Paths to ignore, defaulting to `/favicon.ico`.
+ * Paths to ignore.
*/
-exports.ignore = ['/favicon.ico'];
+exports.ignore = [];
/**
* Setup session store with the given `options`.
@@ -10,7 +10,8 @@
* Module dependencies.
*/
-var Session = require('./session')
+var EventEmitter = require('events').EventEmitter
+ , Session = require('./session')
, Cookie = require('./cookie')
, utils = require('../../utils');
@@ -23,6 +24,12 @@ var Session = require('./session')
var Store = module.exports = function Store(options){};
/**
+ * Inherit from `EventEmitter.prototype`.
+ */
+
+Store.prototype.__proto__ = EventEmitter.prototype;
+
+/**
* Re-generate the given requests's session.
*
* @param {IncomingRequest} req
@@ -39,6 +46,26 @@ Store.prototype.regenerate = function(req, fn){
};
/**
+ * Load a `Session` instance via the given `sid`
+ * and invoke the callback `fn(err, sess)`.
+ *
+ * @param {String} sid
+ * @param {Function} fn
+ * @api public
+ */
+
+Store.prototype.load = function(sid, fn){
+ var self = this;
+ this.get(sid, function(err, sess){
+ if (err) return fn(err);
+ if (!sess) return fn();
+ var req = { sessionID: sid, sessionStore: self };
+ sess = self.createSession(req, sess, false);
+ fn(null, sess);
+ });
+};
+
+/**
* Create session from JSON `sess` data.
*
* @param {IncomingRequest} req
@@ -47,13 +74,14 @@ Store.prototype.regenerate = function(req, fn){
* @api private
*/
-Store.prototype.createSession = function(req, sess){
+Store.prototype.createSession = function(req, sess, update){
var expires = sess.cookie.expires
- , orig = sess.cookie.originalMaxAge;
+ , orig = sess.cookie.originalMaxAge
+ , update = null == update ? true : false;
sess.cookie = new Cookie(sess.cookie);
if ('string' == typeof expires) sess.cookie.expires = new Date(expires);
sess.cookie.originalMaxAge = orig;
req.session = new Session(req, sess);
- req.session.resetLastAccess();
+ if (update) req.session.resetLastAccess();
return req.session;
};
Oops, something went wrong. Retry.

0 comments on commit 4d62409

Please sign in to comment.