Permalink
Browse files

docs

  • Loading branch information...
1 parent 66d4503 commit e97cf7073f0fa0abc95126aa42a265bd2f28142a @tj tj committed Oct 25, 2012
View
@@ -44,7 +44,10 @@
if (!authorization) return unauthorized(res, realm);
var parts = authorization.split(' ')
- , scheme = parts[0]
+
+ if (parts.length !== 2) return next(utils.error(400));
+
+ var scheme = parts[0]
, credentials = new Buffer(parts[1], 'base64').toString().split(':')
, user = credentials[0]
, pass = credentials[1];
View
@@ -58,6 +58,11 @@
};
res.on('header', function(){
+ var encoding = res.getHeader('Content-Encoding') || 'identity';
+
+ // already encoded
+ if ('identity' != encoding) return;
+
// default request filter
if (!filter(req, res)) return;
View
@@ -1,4 +1,4 @@
-<!DOCTYPE html><html><head><title>Connect - High quality middleware for node.js</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><link rel="stylesheet" href="style.css"><script src="jquery.js"></script><script src="docs.js"></script></head><body><div id="content"><h1>Connect</h1><div id="exports.version" class="comment"><h2>exports.version</h2><div class="description"><p>Framework version.</p></div><h3>Source</h3><pre><code>exports.version = '2.4.3';</code></pre></div><div id="exports.mime" class="comment"><h2>exports.mime</h2><div class="description"><p>Expose mime module.</p></div><h3>Source</h3><pre><code>exports.mime = require('./middleware/static').mime;</code></pre></div><div id="exports.proto" class="comment"><h2>exports.proto</h2><div class="description"><p>Expose the prototype.</p></div><h3>Source</h3><pre><code>exports.proto = proto;</code></pre></div><div id="exports.middleware" class="comment"><h2>exports.middleware</h2><div class="description"><p>Auto-load middleware getters.</p></div><h3>Source</h3><pre><code>exports.middleware = {};</code></pre></div><div id="exports.utils" class="comment"><h2>exports.utils</h2><div class="description"><p>Expose utilities.</p></div><h3>Source</h3><pre><code>exports.utils = utils;</code></pre></div><div id="createServer" class="comment"><h2>createServer()</h2><div class="description"><p>Create a new connect server.</p></div><ul class="tags"><li>returns <em>Function</em> </li></ul><h3>Source</h3><pre><code>function createServer() {
+<!DOCTYPE html><html><head><title>Connect - High quality middleware for node.js</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><link rel="stylesheet" href="style.css"><script src="jquery.js"></script><script src="docs.js"></script></head><body><div id="content"><h1>Connect</h1><div id="exports.version" class="comment"><h2>exports.version</h2><div class="description"><p>Framework version.</p></div><h3>Source</h3><pre><code>exports.version = '2.6.0';</code></pre></div><div id="exports.mime" class="comment"><h2>exports.mime</h2><div class="description"><p>Expose mime module.</p></div><h3>Source</h3><pre><code>exports.mime = require('./middleware/static').mime;</code></pre></div><div id="exports.proto" class="comment"><h2>exports.proto</h2><div class="description"><p>Expose the prototype.</p></div><h3>Source</h3><pre><code>exports.proto = proto;</code></pre></div><div id="exports.middleware" class="comment"><h2>exports.middleware</h2><div class="description"><p>Auto-load middleware getters.</p></div><h3>Source</h3><pre><code>exports.middleware = {};</code></pre></div><div id="exports.utils" class="comment"><h2>exports.utils</h2><div class="description"><p>Expose utilities.</p></div><h3>Source</h3><pre><code>exports.utils = utils;</code></pre></div><div id="createServer" class="comment"><h2>createServer()</h2><div class="description"><p>Create a new connect server.</p></div><ul class="tags"><li>returns <em>Function</em> </li></ul><h3>Source</h3><pre><code>function createServer() {
function app(req, res){ app.handle(req, res); }
utils.merge(app, proto);
utils.merge(app, EventEmitter.prototype);
View
@@ -28,6 +28,7 @@
}
req.cookies = utils.parseJSONCookies(req.cookies);
} catch (err) {
+ err.status = 400;
return next(err);
}
}
View
@@ -82,7 +82,7 @@
if (originalHash == crc16(val)) return debug('unmodified session');
// set-cookie
- val = 's:' + utils.sign(val, secret);
+ val = 's:' + signature.sign(val, secret);
val = cookie.serialize(key, val);
debug('set-cookie %j', cookie);
res.setHeader('Set-Cookie', val);
View
@@ -44,7 +44,10 @@
if (!authorization) return unauthorized(res, realm);
var parts = authorization.split(' ')
- , scheme = parts[0]
+
+ if (parts.length !== 2) return next(utils.error(400));
+
+ var scheme = parts[0]
, credentials = new Buffer(parts[1], 'base64').toString().split(':')
, user = credentials[0]
, pass = credentials[1];
View
@@ -58,6 +58,11 @@
};
res.on('header', function(){
+ var encoding = res.getHeader('Content-Encoding') || 'identity';
+
+ // already encoded
+ if ('identity' != encoding) return;
+
// default request filter
if (!filter(req, res)) return;
View
@@ -1,4 +1,4 @@
-<!DOCTYPE html><html><head><title>Connect - High quality middleware for node.js</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><link rel="stylesheet" href="style.css"><script src="jquery.js"></script><script src="docs.js"></script></head><body><div id="content"><h1>Connect</h1><div id="exports.version" class="comment"><h2>exports.version</h2><div class="description"><p>Framework version.</p></div><h3>Source</h3><pre><code>exports.version = '2.4.3';</code></pre></div><div id="exports.mime" class="comment"><h2>exports.mime</h2><div class="description"><p>Expose mime module.</p></div><h3>Source</h3><pre><code>exports.mime = require('./middleware/static').mime;</code></pre></div><div id="exports.proto" class="comment"><h2>exports.proto</h2><div class="description"><p>Expose the prototype.</p></div><h3>Source</h3><pre><code>exports.proto = proto;</code></pre></div><div id="exports.middleware" class="comment"><h2>exports.middleware</h2><div class="description"><p>Auto-load middleware getters.</p></div><h3>Source</h3><pre><code>exports.middleware = {};</code></pre></div><div id="exports.utils" class="comment"><h2>exports.utils</h2><div class="description"><p>Expose utilities.</p></div><h3>Source</h3><pre><code>exports.utils = utils;</code></pre></div><div id="createServer" class="comment"><h2>createServer()</h2><div class="description"><p>Create a new connect server.</p></div><ul class="tags"><li>returns <em>Function</em> </li></ul><h3>Source</h3><pre><code>function createServer() {
+<!DOCTYPE html><html><head><title>Connect - High quality middleware for node.js</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><link rel="stylesheet" href="style.css"><script src="jquery.js"></script><script src="docs.js"></script></head><body><div id="content"><h1>Connect</h1><div id="exports.version" class="comment"><h2>exports.version</h2><div class="description"><p>Framework version.</p></div><h3>Source</h3><pre><code>exports.version = '2.6.0';</code></pre></div><div id="exports.mime" class="comment"><h2>exports.mime</h2><div class="description"><p>Expose mime module.</p></div><h3>Source</h3><pre><code>exports.mime = require('./middleware/static').mime;</code></pre></div><div id="exports.proto" class="comment"><h2>exports.proto</h2><div class="description"><p>Expose the prototype.</p></div><h3>Source</h3><pre><code>exports.proto = proto;</code></pre></div><div id="exports.middleware" class="comment"><h2>exports.middleware</h2><div class="description"><p>Auto-load middleware getters.</p></div><h3>Source</h3><pre><code>exports.middleware = {};</code></pre></div><div id="exports.utils" class="comment"><h2>exports.utils</h2><div class="description"><p>Expose utilities.</p></div><h3>Source</h3><pre><code>exports.utils = utils;</code></pre></div><div id="createServer" class="comment"><h2>createServer()</h2><div class="description"><p>Create a new connect server.</p></div><ul class="tags"><li>returns <em>Function</em> </li></ul><h3>Source</h3><pre><code>function createServer() {
function app(req, res){ app.handle(req, res); }
utils.merge(app, proto);
utils.merge(app, EventEmitter.prototype);
@@ -28,6 +28,7 @@
}
req.cookies = utils.parseJSONCookies(req.cookies);
} catch (err) {
+ err.status = 400;
return next(err);
}
}
@@ -82,7 +82,7 @@
if (originalHash == crc16(val)) return debug('unmodified session');
// set-cookie
- val = 's:' + utils.sign(val, secret);
+ val = 's:' + signature.sign(val, secret);
val = cookie.serialize(key, val);
debug('set-cookie %j', cookie);
res.setHeader('Set-Cookie', val);
View
@@ -18,14 +18,14 @@
<ul>
<li><a href="logger.html">logger</a> request logger with custom format support</li>
-<li><a href="timeout.html">timeout</a> request timeout support</li>
<li><a href="csrf.html">csrf</a> Cross-site request forgery protection</li>
<li><a href="compress.html">compress</a> Gzip compression middleware</li>
<li><a href="basicAuth.html">basicAuth</a> basic http authentication</li>
<li><a href="bodyParser.html">bodyParser</a> extensible request body parser</li>
<li><a href="json.html">json</a> application/json parser</li>
<li><a href="urlencoded.html">urlencoded</a> application/x-www-form-urlencoded parser</li>
<li><a href="multipart.html">multipart</a> multipart/form-data parser</li>
+<li><a href="timeout.html">timeout</a> request timeouts</li>
<li><a href="cookieParser.html">cookieParser</a> cookie parser</li>
<li><a href="session.html">session</a> session management support with bundled MemoryStore</li>
<li><a href="cookieSession.html">cookieSession</a> cookie-based session support</li>
View
@@ -93,7 +93,7 @@
// flush interval
setInterval(function(){
if (buf.length) {
- realStream.write(buf.join(''), 'ascii');
+ realStream.write(buf.join(''));
buf.length = 0;
}
}, interval);
@@ -113,7 +113,7 @@
if (immediate) {
var line = fmt(exports, req, res);
if (null == line) return;
- stream.write(line + '\n', 'ascii');
+ stream.write(line + '\n');
// proxy end to output logging
} else {
var end = res.end;
@@ -122,7 +122,7 @@
res.end(chunk, encoding);
var line = fmt(exports, req, res);
if (null == line) return;
- stream.write(line + '\n', 'ascii');
+ stream.write(line + '\n');
};
}
@@ -162,7 +162,7 @@
+ 'ms' + len
+ '\033[0m';
});</code></pre></div><div id="" class="comment"><h2></h2><div class="description"><p>request url</p></div><h3>Source</h3><pre><code>exports.token('url', function(req){
- return req.originalUrl;
+ return req.originalUrl || req.url;
});</code></pre></div><div id="" class="comment"><h2></h2><div class="description"><p>request method</p></div><h3>Source</h3><pre><code>exports.token('method', function(req){
return req.method;
});</code></pre></div><div id="" class="comment"><h2></h2><div class="description"><p>response time in milliseconds</p></div><h3>Source</h3><pre><code>exports.token('response-time', function(req){
View
@@ -15,6 +15,9 @@
<ul>
<li><code>limit</code> byte limit defaulting to none</li>
+<li><code>defer</code> defers processing and exposes the Formidable form object as <code>req.form</code>.
+ <code>next()</code> is called without waiting for the form's "end" event.
+ This option is useful if you need to bind to the "progress" event, for example.</li>
</ul></div><ul class="tags"><li><em>Object</em> options </li><li>returns <em>Function</em> </li></ul><h3>Source</h3><pre><code>exports = module.exports = function(options){
options = options || {};
@@ -68,7 +71,10 @@
});
form.on('error', function(err){
- next(err);
+ if (!options.defer) {
+ err.status = 400;
+ next(err);
+ }
done = true;
});
@@ -77,13 +83,18 @@
try {
req.body = qs.parse(data);
req.files = qs.parse(files);
- next();
+ if (!options.defer) next();
} catch (err) {
- next(err);
+ form.emit('error', err);
}
});
form.parse(req);
+
+ if (options.defer) {
+ req.form = form;
+ next();
+ }
});
}
};</code></pre></div></div><ul id="menu"><li><a href="#noop">noop()</a></li><li><a href="#"></a></li></ul></body></html>
View
@@ -17,7 +17,7 @@
<p>This api is chainable, so the following is valid:</p>
-<pre><code> connect
+<pre><code> connect()
.use(connect.favicon())
.use(connect.logger())
.use(connect.static(__dirname + '/public'))
@@ -116,7 +116,7 @@
if (undefined == path) path = '/';
// skip this layer if the route doesn't match.
- if (0 != path.indexOf(layer.route)) return next(err);
+ if (0 != path.toLowerCase().indexOf(layer.route)) return next(err);
c = path[layer.route.length];
if (c && '/' != c && '.' != c) return next(err);
@@ -9,7 +9,7 @@
res.on('header', function(header){
var duration = new Date - start;
- res.setHeader('X-Response-time', duration + 'ms');
+ res.setHeader('X-Response-Time', duration + 'ms');
});
next();
View
@@ -135,7 +135,8 @@
, key = options.key || 'connect.sid'
, store = options.store || new MemoryStore
, cookie = options.cookie || {}
- , trustProxy = options.proxy;
+ , trustProxy = options.proxy
+ , storeReady = true;
// notify user that this store is not
// meant for a production environment
@@ -150,10 +151,17 @@
req.session.cookie = new Cookie(cookie);
};
+ store.on('disconnect', function(){ storeReady = false; });
+ store.on('connect', function(){ storeReady = true; });
+
return function session(req, res, next) {
// self-awareness
if (req.session) return next();
+ // Handle connection as if there is no session if
+ // the store has temporarily disconnected etc
+ if (!storeReady) return next();
+
// pathname mismatch
if (0 != req.originalUrl.indexOf(cookie.path || '/')) return next();
@@ -202,7 +210,7 @@
return debug('unmodified session');
}
- var val = 's:' + utils.sign(req.sessionID, secret);
+ var val = 's:' + signature.sign(req.sessionID, secret);
val = cookie.serialize(key, val);
debug('set-cookie %s', val);
res.setHeader('Set-Cookie', val);
View
@@ -31,17 +31,23 @@
return function static(req, res, next) {
if ('GET' != req.method && 'HEAD' != req.method) return next();
var path = parse(req).pathname;
+ var pause = utils.pause(req);
+
+ function resume() {
+ next();
+ pause.resume();
+ }
function directory() {
- if (!redirect) return next();
+ if (!redirect) return resume();
var pathname = url.parse(req.originalUrl).pathname;
res.statusCode = 301;
res.setHeader('Location', pathname + '/');
res.end('Redirecting to ' + utils.escape(pathname) + '/');
}
function error(err) {
- if (404 == err.status) return next();
+ if (404 == err.status) return resume();
next(err);
}
View
@@ -43,12 +43,14 @@
.toString('base64')
.slice(0, len);
};</code></pre></div><div id="exports.sign" class="comment"><h2>exports.sign()</h2><div class="description"><p>Sign the given <code>val</code> with <code>secret</code>.</p></div><ul class="tags"><li><em>String</em> val </li><li><em>String</em> secret </li><li>returns <em>String</em> </li></ul><h3>Source</h3><pre><code>exports.sign = function(val, secret){
+ console.warn('do not use utils.sign(), use https://github.com/visionmedia/node-cookie-signature')
return val + '.' + crypto
.createHmac('sha256', secret)
.update(val)
.digest('base64')
.replace(/=+$/, '');
};</code></pre></div><div id="exports.unsign" class="comment"><h2>exports.unsign()</h2><div class="description"><p>Unsign and decode the given <code>val</code> with <code>secret</code>,<br />returning <code>false</code> if the signature is invalid.</p></div><ul class="tags"><li><em>String</em> val </li><li><em>String</em> secret </li><li>returns <em>String | Boolean</em> </li></ul><h3>Source</h3><pre><code>exports.unsign = function(val, secret){
+ console.warn('do not use utils.unsign(), use https://github.com/visionmedia/node-cookie-signature')
var str = val.slice(0, val.lastIndexOf('.'));
return exports.sign(str, secret) == val
? str
@@ -58,7 +60,7 @@
Object.keys(obj).forEach(function(key){
var val = obj[key];
if (0 == val.indexOf('s:')) {
- val = exports.unsign(val.slice(2), secret);
+ val = signature.unsign(val.slice(2), secret);
if (val) {
ret[key] = val;
delete obj[key];
@@ -68,7 +70,7 @@
return ret;
};</code></pre></div><div id="exports.parseSignedCookie" class="comment"><h2>exports.parseSignedCookie()</h2><div class="description"><p>Parse a signed cookie string, return the decoded value</p></div><ul class="tags"><li><em>String</em> str signed cookie string</li><li><em>String</em> secret </li><li>returns <em>String</em> decoded value</li></ul><h3>Source</h3><pre><code>exports.parseSignedCookie = function(str, secret){
return 0 == str.indexOf('s:')
- ? exports.unsign(str.slice(2), secret)
+ ? signature.unsign(str.slice(2), secret)
: str;
};</code></pre></div><div id="exports.parseJSONCookies" class="comment"><h2>exports.parseJSONCookies()</h2><div class="description"><p>Parse JSON cookies.</p></div><ul class="tags"><li><em>Object</em> obj </li><li>returns <em>Object</em> </li></ul><h3>Source</h3><pre><code>exports.parseJSONCookies = function(obj){
Object.keys(obj).forEach(function(key){
View
@@ -18,14 +18,14 @@
<ul>
<li><a href="logger.html">logger</a> request logger with custom format support</li>
-<li><a href="timeout.html">timeout</a> request timeout support</li>
<li><a href="csrf.html">csrf</a> Cross-site request forgery protection</li>
<li><a href="compress.html">compress</a> Gzip compression middleware</li>
<li><a href="basicAuth.html">basicAuth</a> basic http authentication</li>
<li><a href="bodyParser.html">bodyParser</a> extensible request body parser</li>
<li><a href="json.html">json</a> application/json parser</li>
<li><a href="urlencoded.html">urlencoded</a> application/x-www-form-urlencoded parser</li>
<li><a href="multipart.html">multipart</a> multipart/form-data parser</li>
+<li><a href="timeout.html">timeout</a> request timeouts</li>
<li><a href="cookieParser.html">cookieParser</a> cookie parser</li>
<li><a href="session.html">session</a> session management support with bundled MemoryStore</li>
<li><a href="cookieSession.html">cookieSession</a> cookie-based session support</li>
View
@@ -93,7 +93,7 @@
// flush interval
setInterval(function(){
if (buf.length) {
- realStream.write(buf.join(''), 'ascii');
+ realStream.write(buf.join(''));
buf.length = 0;
}
}, interval);
@@ -113,7 +113,7 @@
if (immediate) {
var line = fmt(exports, req, res);
if (null == line) return;
- stream.write(line + '\n', 'ascii');
+ stream.write(line + '\n');
// proxy end to output logging
} else {
var end = res.end;
@@ -122,7 +122,7 @@
res.end(chunk, encoding);
var line = fmt(exports, req, res);
if (null == line) return;
- stream.write(line + '\n', 'ascii');
+ stream.write(line + '\n');
};
}
@@ -162,7 +162,7 @@
+ 'ms' + len
+ '\033[0m';
});</code></pre></div><div id="" class="comment"><h2></h2><div class="description"><p>request url</p></div><h3>Source</h3><pre><code>exports.token('url', function(req){
- return req.originalUrl;
+ return req.originalUrl || req.url;
});</code></pre></div><div id="" class="comment"><h2></h2><div class="description"><p>request method</p></div><h3>Source</h3><pre><code>exports.token('method', function(req){
return req.method;
});</code></pre></div><div id="" class="comment"><h2></h2><div class="description"><p>response time in milliseconds</p></div><h3>Source</h3><pre><code>exports.token('response-time', function(req){
Oops, something went wrong.

0 comments on commit e97cf70

Please sign in to comment.