Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

docs

  • Loading branch information...
commit e97cf7073f0fa0abc95126aa42a265bd2f28142a 1 parent 66d4503
TJ Holowaychuk authored October 25, 2012
5  basicAuth.html
@@ -44,7 +44,10 @@
44 44
     if (!authorization) return unauthorized(res, realm);
45 45
 
46 46
     var parts = authorization.split(' ')
47  
-      , scheme = parts[0]
  47
+
  48
+    if (parts.length !== 2) return next(utils.error(400));
  49
+
  50
+    var scheme = parts[0]
48 51
       , credentials = new Buffer(parts[1], 'base64').toString().split(':')
49 52
       , user = credentials[0]
50 53
       , pass = credentials[1];
5  compress.html
@@ -58,6 +58,11 @@
58 58
     };
59 59
 
60 60
     res.on('header', function(){
  61
+      var encoding = res.getHeader('Content-Encoding') || 'identity';
  62
+
  63
+      // already encoded
  64
+      if ('identity' != encoding) return; 
  65
+
61 66
       // default request filter
62 67
       if (!filter(req, res)) return;
63 68
 
2  connect.html
... ...
@@ -1,4 +1,4 @@
1  
-<!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() {
  1
+<!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() {
2 2
   function app(req, res){ app.handle(req, res); }
3 3
   utils.merge(app, proto);
4 4
   utils.merge(app, EventEmitter.prototype);
1  cookieParser.html
@@ -28,6 +28,7 @@
28 28
         }
29 29
         req.cookies = utils.parseJSONCookies(req.cookies);
30 30
       } catch (err) {
  31
+        err.status = 400;
31 32
         return next(err);
32 33
       }
33 34
     }
2  cookieSession.html
@@ -82,7 +82,7 @@
82 82
       if (originalHash == crc16(val)) return debug('unmodified session');
83 83
 
84 84
       // set-cookie
85  
-      val = 's:' + utils.sign(val, secret);
  85
+      val = 's:' + signature.sign(val, secret);
86 86
       val = cookie.serialize(key, val);
87 87
       debug('set-cookie %j', cookie);
88 88
       res.setHeader('Set-Cookie', val);
5  docs/basicAuth.html
@@ -44,7 +44,10 @@
44 44
     if (!authorization) return unauthorized(res, realm);
45 45
 
46 46
     var parts = authorization.split(' ')
47  
-      , scheme = parts[0]
  47
+
  48
+    if (parts.length !== 2) return next(utils.error(400));
  49
+
  50
+    var scheme = parts[0]
48 51
       , credentials = new Buffer(parts[1], 'base64').toString().split(':')
49 52
       , user = credentials[0]
50 53
       , pass = credentials[1];
5  docs/compress.html
@@ -58,6 +58,11 @@
58 58
     };
59 59
 
60 60
     res.on('header', function(){
  61
+      var encoding = res.getHeader('Content-Encoding') || 'identity';
  62
+
  63
+      // already encoded
  64
+      if ('identity' != encoding) return; 
  65
+
61 66
       // default request filter
62 67
       if (!filter(req, res)) return;
63 68
 
2  docs/connect.html
... ...
@@ -1,4 +1,4 @@
1  
-<!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() {
  1
+<!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() {
2 2
   function app(req, res){ app.handle(req, res); }
3 3
   utils.merge(app, proto);
4 4
   utils.merge(app, EventEmitter.prototype);
1  docs/cookieParser.html
@@ -28,6 +28,7 @@
28 28
         }
29 29
         req.cookies = utils.parseJSONCookies(req.cookies);
30 30
       } catch (err) {
  31
+        err.status = 400;
31 32
         return next(err);
32 33
       }
33 34
     }
2  docs/cookieSession.html
@@ -82,7 +82,7 @@
82 82
       if (originalHash == crc16(val)) return debug('unmodified session');
83 83
 
84 84
       // set-cookie
85  
-      val = 's:' + utils.sign(val, secret);
  85
+      val = 's:' + signature.sign(val, secret);
86 86
       val = cookie.serialize(key, val);
87 87
       debug('set-cookie %j', cookie);
88 88
       res.setHeader('Set-Cookie', val);
2  docs/index.html
@@ -18,7 +18,6 @@
18 18
 
19 19
 <ul>
20 20
 <li><a href="logger.html">logger</a> request logger with custom format support</li>
21  
-<li><a href="timeout.html">timeout</a> request timeout support</li>
22 21
 <li><a href="csrf.html">csrf</a> Cross-site request forgery protection</li>
23 22
 <li><a href="compress.html">compress</a> Gzip compression middleware</li>
24 23
 <li><a href="basicAuth.html">basicAuth</a> basic http authentication</li>
@@ -26,6 +25,7 @@
26 25
 <li><a href="json.html">json</a> application/json parser</li>
27 26
 <li><a href="urlencoded.html">urlencoded</a> application/x-www-form-urlencoded parser</li>
28 27
 <li><a href="multipart.html">multipart</a> multipart/form-data parser</li>
  28
+<li><a href="timeout.html">timeout</a> request timeouts</li>
29 29
 <li><a href="cookieParser.html">cookieParser</a> cookie parser</li>
30 30
 <li><a href="session.html">session</a> session management support with bundled MemoryStore</li>
31 31
 <li><a href="cookieSession.html">cookieSession</a> cookie-based session support</li>
8  docs/logger.html
@@ -93,7 +93,7 @@
93 93
     // flush interval
94 94
     setInterval(function(){
95 95
       if (buf.length) {
96  
-        realStream.write(buf.join(''), 'ascii');
  96
+        realStream.write(buf.join(''));
97 97
         buf.length = 0;
98 98
       }
99 99
     }, interval); 
@@ -113,7 +113,7 @@
113 113
     if (immediate) {
114 114
       var line = fmt(exports, req, res);
115 115
       if (null == line) return;
116  
-      stream.write(line + '\n', 'ascii');
  116
+      stream.write(line + '\n');
117 117
     // proxy end to output logging
118 118
     } else {
119 119
       var end = res.end;
@@ -122,7 +122,7 @@
122 122
         res.end(chunk, encoding);
123 123
         var line = fmt(exports, req, res);
124 124
         if (null == line) return;
125  
-        stream.write(line + '\n', 'ascii');
  125
+        stream.write(line + '\n');
126 126
       };
127 127
     }
128 128
 
@@ -162,7 +162,7 @@
162 162
     + 'ms' + len
163 163
     + '\033[0m';
164 164
 });</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){
165  
-  return req.originalUrl;
  165
+  return req.originalUrl || req.url;
166 166
 });</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){
167 167
   return req.method;
168 168
 });</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){
17  docs/multipart.html
@@ -15,6 +15,9 @@
15 15
 
16 16
 <ul>
17 17
 <li><code>limit</code>  byte limit defaulting to none</li>
  18
+<li><code>defer</code>  defers processing and exposes the Formidable form object as <code>req.form</code>.
  19
+         <code>next()</code> is called without waiting for the form's "end" event.
  20
+         This option is useful if you need to bind to the "progress" event, for example.</li>
18 21
 </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){
19 22
   options = options || {};
20 23
 
@@ -68,7 +71,10 @@
68 71
       });
69 72
 
70 73
       form.on('error', function(err){
71  
-        next(err);
  74
+        if (!options.defer) {
  75
+          err.status = 400;
  76
+          next(err);
  77
+        }
72 78
         done = true;
73 79
       });
74 80
 
@@ -77,13 +83,18 @@
77 83
         try {
78 84
           req.body = qs.parse(data);
79 85
           req.files = qs.parse(files);
80  
-          next();
  86
+          if (!options.defer) next();
81 87
         } catch (err) {
82  
-          next(err);
  88
+          form.emit('error', err);
83 89
         }
84 90
       });
85 91
 
86 92
       form.parse(req);
  93
+
  94
+      if (options.defer) {
  95
+        req.form = form;
  96
+        next();
  97
+      }
87 98
     });
88 99
   }
89 100
 };</code></pre></div></div><ul id="menu"><li><a href="#noop">noop()</a></li><li><a href="#"></a></li></ul></body></html>
4  docs/proto.html
@@ -17,7 +17,7 @@
17 17
 
18 18
 <p>This api is chainable, so the following is valid:</p>
19 19
 
20  
-<pre><code> connect
  20
+<pre><code> connect()
21 21
    .use(connect.favicon())
22 22
    .use(connect.logger())
23 23
    .use(connect.static(__dirname + '/public'))
@@ -116,7 +116,7 @@
116 116
       if (undefined == path) path = '/';
117 117
 
118 118
       // skip this layer if the route doesn't match.
119  
-      if (0 != path.indexOf(layer.route)) return next(err);
  119
+      if (0 != path.toLowerCase().indexOf(layer.route)) return next(err);
120 120
 
121 121
       c = path[layer.route.length];
122 122
       if (c && '/' != c && '.' != c) return next(err);
2  docs/responseTime.html
@@ -9,7 +9,7 @@
9 9
 
10 10
     res.on('header', function(header){
11 11
       var duration = new Date - start;
12  
-      res.setHeader('X-Response-time', duration + 'ms');
  12
+      res.setHeader('X-Response-Time', duration + 'ms');
13 13
     });
14 14
 
15 15
     next();
12  docs/session.html
@@ -135,7 +135,8 @@
135 135
     , key = options.key || 'connect.sid'
136 136
     , store = options.store || new MemoryStore
137 137
     , cookie = options.cookie || {}
138  
-    , trustProxy = options.proxy;
  138
+    , trustProxy = options.proxy
  139
+    , storeReady = true;
139 140
 
140 141
   // notify user that this store is not
141 142
   // meant for a production environment
@@ -150,10 +151,17 @@
150 151
     req.session.cookie = new Cookie(cookie);
151 152
   };
152 153
 
  154
+  store.on('disconnect', function(){ storeReady = false; });
  155
+  store.on('connect', function(){ storeReady = true; });
  156
+
153 157
   return function session(req, res, next) {
154 158
     // self-awareness
155 159
     if (req.session) return next();
156 160
 
  161
+    // Handle connection as if there is no session if
  162
+    // the store has temporarily disconnected etc
  163
+    if (!storeReady) return next();
  164
+
157 165
     // pathname mismatch
158 166
     if (0 != req.originalUrl.indexOf(cookie.path || '/')) return next();
159 167
 
@@ -202,7 +210,7 @@
202 210
         return debug('unmodified session');
203 211
       }
204 212
 
205  
-      var val = 's:' + utils.sign(req.sessionID, secret);
  213
+      var val = 's:' + signature.sign(req.sessionID, secret);
206 214
       val = cookie.serialize(key, val);
207 215
       debug('set-cookie %s', val);
208 216
       res.setHeader('Set-Cookie', val);
10  docs/static.html
@@ -31,9 +31,15 @@
31 31
   return function static(req, res, next) {
32 32
     if ('GET' != req.method && 'HEAD' != req.method) return next();
33 33
     var path = parse(req).pathname;
  34
+    var pause = utils.pause(req);
  35
+
  36
+    function resume() {
  37
+      next();
  38
+      pause.resume();
  39
+    }
34 40
 
35 41
     function directory() {
36  
-      if (!redirect) return next();
  42
+      if (!redirect) return resume();
37 43
       var pathname = url.parse(req.originalUrl).pathname;
38 44
       res.statusCode = 301;
39 45
       res.setHeader('Location', pathname + '/');
@@ -41,7 +47,7 @@
41 47
     }
42 48
 
43 49
     function error(err) {
44  
-      if (404 == err.status) return next();
  50
+      if (404 == err.status) return resume();
45 51
       next(err);
46 52
     }
47 53
 
6  docs/utils.html
@@ -43,12 +43,14 @@
43 43
     .toString('base64')
44 44
     .slice(0, len);
45 45
 };</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){
  46
+  console.warn('do not use utils.sign(), use https://github.com/visionmedia/node-cookie-signature')
46 47
   return val + '.' + crypto
47 48
     .createHmac('sha256', secret)
48 49
     .update(val)
49 50
     .digest('base64')
50 51
     .replace(/=+$/, '');
51 52
 };</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){
  53
+  console.warn('do not use utils.unsign(), use https://github.com/visionmedia/node-cookie-signature')
52 54
   var str = val.slice(0, val.lastIndexOf('.'));
53 55
   return exports.sign(str, secret) == val
54 56
     ? str
@@ -58,7 +60,7 @@
58 60
   Object.keys(obj).forEach(function(key){
59 61
     var val = obj[key];
60 62
     if (0 == val.indexOf('s:')) {
61  
-      val = exports.unsign(val.slice(2), secret);
  63
+      val = signature.unsign(val.slice(2), secret);
62 64
       if (val) {
63 65
         ret[key] = val;
64 66
         delete obj[key];
@@ -68,7 +70,7 @@
68 70
   return ret;
69 71
 };</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){
70 72
   return 0 == str.indexOf('s:')
71  
-    ? exports.unsign(str.slice(2), secret)
  73
+    ? signature.unsign(str.slice(2), secret)
72 74
     : str;
73 75
 };</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){
74 76
   Object.keys(obj).forEach(function(key){
2  index.html
@@ -18,7 +18,6 @@
18 18
 
19 19
 <ul>
20 20
 <li><a href="logger.html">logger</a> request logger with custom format support</li>
21  
-<li><a href="timeout.html">timeout</a> request timeout support</li>
22 21
 <li><a href="csrf.html">csrf</a> Cross-site request forgery protection</li>
23 22
 <li><a href="compress.html">compress</a> Gzip compression middleware</li>
24 23
 <li><a href="basicAuth.html">basicAuth</a> basic http authentication</li>
@@ -26,6 +25,7 @@
26 25
 <li><a href="json.html">json</a> application/json parser</li>
27 26
 <li><a href="urlencoded.html">urlencoded</a> application/x-www-form-urlencoded parser</li>
28 27
 <li><a href="multipart.html">multipart</a> multipart/form-data parser</li>
  28
+<li><a href="timeout.html">timeout</a> request timeouts</li>
29 29
 <li><a href="cookieParser.html">cookieParser</a> cookie parser</li>
30 30
 <li><a href="session.html">session</a> session management support with bundled MemoryStore</li>
31 31
 <li><a href="cookieSession.html">cookieSession</a> cookie-based session support</li>
8  logger.html
@@ -93,7 +93,7 @@
93 93
     // flush interval
94 94
     setInterval(function(){
95 95
       if (buf.length) {
96  
-        realStream.write(buf.join(''), 'ascii');
  96
+        realStream.write(buf.join(''));
97 97
         buf.length = 0;
98 98
       }
99 99
     }, interval); 
@@ -113,7 +113,7 @@
113 113
     if (immediate) {
114 114
       var line = fmt(exports, req, res);
115 115
       if (null == line) return;
116  
-      stream.write(line + '\n', 'ascii');
  116
+      stream.write(line + '\n');
117 117
     // proxy end to output logging
118 118
     } else {
119 119
       var end = res.end;
@@ -122,7 +122,7 @@
122 122
         res.end(chunk, encoding);
123 123
         var line = fmt(exports, req, res);
124 124
         if (null == line) return;
125  
-        stream.write(line + '\n', 'ascii');
  125
+        stream.write(line + '\n');
126 126
       };
127 127
     }
128 128
 
@@ -162,7 +162,7 @@
162 162
     + 'ms' + len
163 163
     + '\033[0m';
164 164
 });</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){
165  
-  return req.originalUrl;
  165
+  return req.originalUrl || req.url;
166 166
 });</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){
167 167
   return req.method;
168 168
 });</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){
17  multipart.html
@@ -15,6 +15,9 @@
15 15
 
16 16
 <ul>
17 17
 <li><code>limit</code>  byte limit defaulting to none</li>
  18
+<li><code>defer</code>  defers processing and exposes the Formidable form object as <code>req.form</code>.
  19
+         <code>next()</code> is called without waiting for the form's "end" event.
  20
+         This option is useful if you need to bind to the "progress" event, for example.</li>
18 21
 </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){
19 22
   options = options || {};
20 23
 
@@ -68,7 +71,10 @@
68 71
       });
69 72
 
70 73
       form.on('error', function(err){
71  
-        next(err);
  74
+        if (!options.defer) {
  75
+          err.status = 400;
  76
+          next(err);
  77
+        }
72 78
         done = true;
73 79
       });
74 80
 
@@ -77,13 +83,18 @@
77 83
         try {
78 84
           req.body = qs.parse(data);
79 85
           req.files = qs.parse(files);
80  
-          next();
  86
+          if (!options.defer) next();
81 87
         } catch (err) {
82  
-          next(err);
  88
+          form.emit('error', err);
83 89
         }
84 90
       });
85 91
 
86 92
       form.parse(req);
  93
+
  94
+      if (options.defer) {
  95
+        req.form = form;
  96
+        next();
  97
+      }
87 98
     });
88 99
   }
89 100
 };</code></pre></div></div><ul id="menu"><li><a href="#noop">noop()</a></li><li><a href="#"></a></li></ul></body></html>
4  proto.html
@@ -17,7 +17,7 @@
17 17
 
18 18
 <p>This api is chainable, so the following is valid:</p>
19 19
 
20  
-<pre><code> connect
  20
+<pre><code> connect()
21 21
    .use(connect.favicon())
22 22
    .use(connect.logger())
23 23
    .use(connect.static(__dirname + '/public'))
@@ -116,7 +116,7 @@
116 116
       if (undefined == path) path = '/';
117 117
 
118 118
       // skip this layer if the route doesn't match.
119  
-      if (0 != path.indexOf(layer.route)) return next(err);
  119
+      if (0 != path.toLowerCase().indexOf(layer.route)) return next(err);
120 120
 
121 121
       c = path[layer.route.length];
122 122
       if (c && '/' != c && '.' != c) return next(err);
2  responseTime.html
@@ -9,7 +9,7 @@
9 9
 
10 10
     res.on('header', function(header){
11 11
       var duration = new Date - start;
12  
-      res.setHeader('X-Response-time', duration + 'ms');
  12
+      res.setHeader('X-Response-Time', duration + 'ms');
13 13
     });
14 14
 
15 15
     next();
12  session.html
@@ -135,7 +135,8 @@
135 135
     , key = options.key || 'connect.sid'
136 136
     , store = options.store || new MemoryStore
137 137
     , cookie = options.cookie || {}
138  
-    , trustProxy = options.proxy;
  138
+    , trustProxy = options.proxy
  139
+    , storeReady = true;
139 140
 
140 141
   // notify user that this store is not
141 142
   // meant for a production environment
@@ -150,10 +151,17 @@
150 151
     req.session.cookie = new Cookie(cookie);
151 152
   };
152 153
 
  154
+  store.on('disconnect', function(){ storeReady = false; });
  155
+  store.on('connect', function(){ storeReady = true; });
  156
+
153 157
   return function session(req, res, next) {
154 158
     // self-awareness
155 159
     if (req.session) return next();
156 160
 
  161
+    // Handle connection as if there is no session if
  162
+    // the store has temporarily disconnected etc
  163
+    if (!storeReady) return next();
  164
+
157 165
     // pathname mismatch
158 166
     if (0 != req.originalUrl.indexOf(cookie.path || '/')) return next();
159 167
 
@@ -202,7 +210,7 @@
202 210
         return debug('unmodified session');
203 211
       }
204 212
 
205  
-      var val = 's:' + utils.sign(req.sessionID, secret);
  213
+      var val = 's:' + signature.sign(req.sessionID, secret);
206 214
       val = cookie.serialize(key, val);
207 215
       debug('set-cookie %s', val);
208 216
       res.setHeader('Set-Cookie', val);
10  static.html
@@ -31,9 +31,15 @@
31 31
   return function static(req, res, next) {
32 32
     if ('GET' != req.method && 'HEAD' != req.method) return next();
33 33
     var path = parse(req).pathname;
  34
+    var pause = utils.pause(req);
  35
+
  36
+    function resume() {
  37
+      next();
  38
+      pause.resume();
  39
+    }
34 40
 
35 41
     function directory() {
36  
-      if (!redirect) return next();
  42
+      if (!redirect) return resume();
37 43
       var pathname = url.parse(req.originalUrl).pathname;
38 44
       res.statusCode = 301;
39 45
       res.setHeader('Location', pathname + '/');
@@ -41,7 +47,7 @@
41 47
     }
42 48
 
43 49
     function error(err) {
44  
-      if (404 == err.status) return next();
  50
+      if (404 == err.status) return resume();
45 51
       next(err);
46 52
     }
47 53
 
31  timeout.html
... ...
@@ -0,0 +1,31 @@
  1
+<!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="module.exports" class="comment"><h2></h2><div class="description"><h2>Timeout</h2>
  2
+
  3
+<p>Times out the request in <code>ms</code>, defaulting to <code>5000</code>. The<br />method <code>req.clearTimeout()</code> is added to revert this behaviour<br />programmatically within your application's middleware, routes, etc.</p>
  4
+
  5
+<p>The timeout error is passed to <code>next()</code> so that you may customize<br />the response behaviour. This error has the <code>.timeout</code> property as<br />well as <code>.status == 408</code>.</p></div><ul class="tags"><li><em>Number</em> ms </li><li>returns <em>Function</em> </li></ul><h3>Source</h3><pre><code>module.exports = function timeout(ms) {
  6
+  ms = ms || 5000;
  7
+
  8
+  return function(req, res, next) {
  9
+    var id = setTimeout(function(){
  10
+      req.emit('timeout', ms);
  11
+    }, ms);
  12
+
  13
+    req.on('timeout', function(){
  14
+      if (req.headerSent) return debug('response started, cannot timeout');
  15
+      var err = new Error('Request timeout');
  16
+      err.timeout = ms;
  17
+      err.status = 408;
  18
+      next(err);
  19
+    });
  20
+
  21
+    req.clearTimeout = function(){
  22
+      clearTimeout(id);
  23
+    };
  24
+
  25
+    res.on('header', function(){
  26
+      clearTimeout(id);
  27
+    });
  28
+
  29
+    next();
  30
+  };
  31
+};</code></pre></div></div><ul id="menu"><li><a href="#module.exports"></a></li></ul></body></html>
6  utils.html
@@ -43,12 +43,14 @@
43 43
     .toString('base64')
44 44
     .slice(0, len);
45 45
 };</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){
  46
+  console.warn('do not use utils.sign(), use https://github.com/visionmedia/node-cookie-signature')
46 47
   return val + '.' + crypto
47 48
     .createHmac('sha256', secret)
48 49
     .update(val)
49 50
     .digest('base64')
50 51
     .replace(/=+$/, '');
51 52
 };</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){
  53
+  console.warn('do not use utils.unsign(), use https://github.com/visionmedia/node-cookie-signature')
52 54
   var str = val.slice(0, val.lastIndexOf('.'));
53 55
   return exports.sign(str, secret) == val
54 56
     ? str
@@ -58,7 +60,7 @@
58 60
   Object.keys(obj).forEach(function(key){
59 61
     var val = obj[key];
60 62
     if (0 == val.indexOf('s:')) {
61  
-      val = exports.unsign(val.slice(2), secret);
  63
+      val = signature.unsign(val.slice(2), secret);
62 64
       if (val) {
63 65
         ret[key] = val;
64 66
         delete obj[key];
@@ -68,7 +70,7 @@
68 70
   return ret;
69 71
 };</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){
70 72
   return 0 == str.indexOf('s:')
71  
-    ? exports.unsign(str.slice(2), secret)
  73
+    ? signature.unsign(str.slice(2), secret)
72 74
     : str;
73 75
 };</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){
74 76
   Object.keys(obj).forEach(function(key){

0 notes on commit e97cf70

Please sign in to comment.
Something went wrong with that request. Please try again.