[Pkg-javascript-commits] [node-connect] 02/09: Imported Upstream version 3.2.0
Leo Iannacone
l3on-guest at moszumanska.debian.org
Fri Oct 17 11:08:28 UTC 2014
This is an automated email from the git hooks/post-receive script.
l3on-guest pushed a commit to branch master
in repository node-connect.
commit e57057039c333b2706d03e1f6c54dd18eb0e60a6
Author: Leo Iannacone <l3on at ubuntu.com>
Date: Fri Oct 17 12:50:06 2014 +0200
Imported Upstream version 3.2.0
---
History.md | 508 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
Readme.md | 53 ++++--
lib/proto.js | 166 +++++++++---------
package.json | 39 ++---
test/mounting.js | 170 ++++++++++++-------
5 files changed, 752 insertions(+), 184 deletions(-)
diff --git a/History.md b/History.md
index aa4c933..c754572 100644
--- a/History.md
+++ b/History.md
@@ -1,3 +1,44 @@
+3.2.0 / 2014-09-08
+==================
+
+ * deps: debug@~2.0.0
+ * deps: finalhandler at 0.2.0
+ - Set `X-Content-Type-Options: nosniff` header
+ - deps: debug@~2.0.0
+
+3.1.1 / 2014-08-10
+==================
+
+ * deps: parseurl@~1.3.0
+
+3.1.0 / 2014-07-22
+==================
+
+ * deps: debug at 1.0.4
+ * deps: finalhandler at 0.1.0
+ - Respond after request fully read
+ - deps: debug at 1.0.4
+ * deps: parseurl@~1.2.0
+ - Cache URLs based on original value
+ - Remove no-longer-needed URL mis-parse work-around
+ - Simplify the "fast-path" `RegExp`
+ * perf: reduce executed logic in routing
+ * perf: refactor location of `try` block
+
+3.0.2 / 2014-07-10
+==================
+
+ * deps: debug at 1.0.3
+ - Add support for multiple wildcards in namespaces
+ * deps: parseurl@~1.1.3
+ - faster parsing of href-only URLs
+
+3.0.1 / 2014-06-19
+==================
+
+ * use `finalhandler` for final response handling
+ * deps: debug at 1.0.2
+
3.0.0 / 2014-05-29
==================
@@ -23,11 +64,476 @@
* remove various private `connect.utils` functions
* drop node.js 0.8 support
+2.26.0 / 2014-09-08
+===================
+
+ * deps: body-parser@~1.8.1
+ - add `parameterLimit` option to `urlencoded` parser
+ - change `urlencoded` extended array limit to 100
+ - make empty-body-handling consistent between chunked requests
+ - respond with 415 when over `parameterLimit` in `urlencoded`
+ - deps: media-typer at 0.3.0
+ - deps: qs at 2.2.3
+ - deps: type-is@~1.5.1
+ * deps: compression@~1.1.0
+ - deps: accepts@~1.1.0
+ - deps: compressible@~2.0.0
+ - deps: debug@~2.0.0
+ * deps: connect-timeout@~1.3.0
+ - deps: debug@~2.0.0
+ * deps: cookie-parser@~1.3.3
+ - deps: cookie-signature at 1.0.5
+ * deps: cookie-signature at 1.0.5
+ * deps: csurf@~1.6.1
+ - add `ignoreMethods` option
+ - bump cookie-signature
+ - csrf-tokens -> csrf
+ - set `code` property on CSRF token errors
+ * deps: debug@~2.0.0
+ * deps: errorhandler@~1.2.0
+ - Display error using `util.inspect` if no other representation
+ - deps: accepts@~1.1.0
+ * deps: express-session@~1.8.1
+ - Do not resave already-saved session at end of request
+ - Prevent session prototype methods from being overwritten
+ - deps: cookie-signature at 1.0.5
+ - deps: debug@~2.0.0
+ * deps: finalhandler at 0.2.0
+ - Set `X-Content-Type-Options: nosniff` header
+ - deps: debug@~2.0.0
+ * deps: fresh at 0.2.4
+ * deps: media-typer at 0.3.0
+ - Throw error when parameter format invalid on parse
+ * deps: method-override@~2.2.0
+ - deps: debug@~2.0.0
+ * deps: morgan@~1.3.0
+ - Assert if `format` is not a function or string
+ * deps: qs at 2.2.3
+ - Fix issue where first empty value in array is discarded
+ * deps: serve-favicon@~2.1.3
+ - Accept string for `maxAge` (converted by `ms`)
+ - Use `etag` to generate `ETag` header
+ - deps: fresh at 0.2.4
+ * deps: serve-index@~1.2.1
+ - Add `debug` messages
+ - Resolve relative paths at middleware setup
+ - deps: accepts@~1.1.0
+ * deps: serve-static@~1.6.1
+ - Add `lastModified` option
+ - deps: send at 0.9.1
+ * deps: type-is@~1.5.1
+ - fix `hasbody` to be true for `content-length: 0`
+ - deps: media-typer at 0.3.0
+ - deps: mime-types@~2.0.1
+ * deps: vhost@~3.0.0
+
+2.25.10 / 2014-09-04
+====================
+
+ * deps: serve-static@~1.5.4
+ - deps: send at 0.8.5
+
+2.25.9 / 2014-08-29
+===================
+
+ * deps: body-parser@~1.6.7
+ - deps: qs at 2.2.2
+ * deps: qs at 2.2.2
+
+2.25.8 / 2014-08-27
+===================
+
+ * deps: body-parser@~1.6.6
+ - deps: qs at 2.2.0
+ * deps: csurf@~1.4.1
+ * deps: qs at 2.2.0
+ - Array parsing fix
+ - Performance improvements
+
+2.25.7 / 2014-08-18
+===================
+
+ * deps: body-parser@~1.6.5
+ - deps: on-finished at 2.1.0
+ * deps: express-session@~1.7.6
+ - Fix exception on `res.end(null)` calls
+ * deps: morgan@~1.2.3
+ - deps: on-finished at 2.1.0
+ * deps: serve-static@~1.5.3
+ - deps: send at 0.8.3
+
+2.25.6 / 2014-08-14
+===================
+
+ * deps: body-parser@~1.6.4
+ - deps: qs at 1.2.2
+ * deps: qs at 1.2.2
+ * deps: serve-static@~1.5.2
+ - deps: send at 0.8.2
+
+2.25.5 / 2014-08-11
+===================
+
+ * Fix backwards compatibility in `logger`
+
+2.25.4 / 2014-08-10
+===================
+
+ * Fix `query` middleware breaking with argument
+ - It never really took one in the first place
+ * deps: body-parser@~1.6.3
+ - deps: qs at 1.2.1
+ * deps: compression@~1.0.11
+ - deps: on-headers@~1.0.0
+ - deps: parseurl@~1.3.0
+ * deps: connect-timeout@~1.2.2
+ - deps: on-headers@~1.0.0
+ * deps: express-session@~1.7.5
+ - Fix parsing original URL
+ - deps: on-headers@~1.0.0
+ - deps: parseurl@~1.3.0
+ * deps: method-override@~2.1.3
+ * deps: on-headers@~1.0.0
+ * deps: parseurl@~1.3.0
+ * deps: qs at 1.2.1
+ * deps: response-time@~2.0.1
+ - deps: on-headers@~1.0.0
+ * deps: serve-index@~1.1.6
+ - Fix URL parsing
+ * deps: serve-static@~1.5.1
+ - Fix parsing of weird `req.originalUrl` values
+ - deps: parseurl@~1.3.0
+ = deps: utils-merge at 1.0.0
+
+2.25.3 / 2014-08-07
+===================
+
+ * deps: multiparty at 3.3.2
+ - Fix potential double-callback
+
+2.25.2 / 2014-08-07
+===================
+
+ * deps: body-parser@~1.6.2
+ - deps: qs at 1.2.0
+ * deps: qs at 1.2.0
+ - Fix parsing array of objects
+
+2.25.1 / 2014-08-06
+===================
+
+ * deps: body-parser@~1.6.1
+ - deps: qs at 1.1.0
+ * deps: qs at 1.1.0
+ - Accept urlencoded square brackets
+ - Accept empty values in implicit array notation
+
+2.25.0 / 2014-08-05
+===================
+
+ * deps: body-parser@~1.6.0
+ - deps: qs at 1.0.2
+ * deps: compression@~1.0.10
+ - Fix upper-case Content-Type characters prevent compression
+ - deps: compressible@~1.1.1
+ * deps: csurf@~1.4.0
+ - Support changing `req.session` after `csurf` middleware
+ - Calling `res.csrfToken()` after `req.session.destroy()` will now work
+ * deps: express-session@~1.7.4
+ - Fix `res.end` patch to call correct upstream `res.write`
+ - Fix response end delay for non-chunked responses
+ * deps: qs at 1.0.2
+ - Complete rewrite
+ - Limits array length to 20
+ - Limits object depth to 5
+ - Limits parameters to 1,000
+ * deps: serve-static@~1.5.0
+ - Add `extensions` option
+ - deps: send at 0.8.1
+
+2.24.3 / 2014-08-04
+===================
+
+ * deps: serve-index@~1.1.5
+ - Fix Content-Length calculation for multi-byte file names
+ - deps: accepts@~1.0.7
+ * deps: serve-static@~1.4.4
+ - Fix incorrect 403 on Windows and Node.js 0.11
+ - deps: send at 0.7.4
+
+2.24.2 / 2014-07-27
+===================
+
+ * deps: body-parser@~1.5.2
+ * deps: depd at 0.4.4
+ - Work-around v8 generating empty stack traces
+ * deps: express-session@~1.7.2
+ * deps: morgan@~1.2.2
+ * deps: serve-static@~1.4.2
+
+2.24.1 / 2014-07-26
+===================
+
+ * deps: body-parser@~1.5.1
+ * deps: depd at 0.4.3
+ - Fix exception when global `Error.stackTraceLimit` is too low
+ * deps: express-session@~1.7.1
+ * deps: morgan@~1.2.1
+ * deps: serve-index@~1.1.4
+ * deps: serve-static@~1.4.1
+
+2.24.0 / 2014-07-22
+===================
+
+ * deps: body-parser@~1.5.0
+ - deps: depd at 0.4.2
+ - deps: iconv-lite at 0.4.4
+ - deps: raw-body at 1.3.0
+ - deps: type-is@~1.3.2
+ * deps: compression@~1.0.9
+ - Add `debug` messages
+ - deps: accepts@~1.0.7
+ * deps: connect-timeout@~1.2.1
+ - Accept string for `time` (converted by `ms`)
+ - deps: debug at 1.0.4
+ * deps: debug at 1.0.4
+ * deps: depd at 0.4.2
+ - Add `TRACE_DEPRECATION` environment variable
+ - Remove non-standard grey color from color output
+ - Support `--no-deprecation` argument
+ - Support `--trace-deprecation` argument
+ * deps: express-session@~1.7.0
+ - Improve session-ending error handling
+ - deps: debug at 1.0.4
+ - deps: depd at 0.4.2
+ * deps: finalhandler at 0.1.0
+ - Respond after request fully read
+ - deps: debug at 1.0.4
+ * deps: method-override@~2.1.2
+ - deps: debug at 1.0.4
+ - deps: parseurl@~1.2.0
+ * deps: morgan@~1.2.0
+ - Add `:remote-user` token
+ - Add `combined` log format
+ - Add `common` log format
+ - Remove non-standard grey color from `dev` format
+ * deps: multiparty at 3.3.1
+ * deps: parseurl@~1.2.0
+ - Cache URLs based on original value
+ - Remove no-longer-needed URL mis-parse work-around
+ - Simplify the "fast-path" `RegExp`
+ * deps: serve-static@~1.4.0
+ - Add `dotfiles` option
+ - deps: parseurl@~1.2.0
+ - deps: send at 0.7.0
+
+2.23.0 / 2014-07-10
+===================
+
+ * deps: debug at 1.0.3
+ - Add support for multiple wildcards in namespaces
+ * deps: express-session@~1.6.4
+ * deps: method-override@~2.1.0
+ - add simple debug output
+ - deps: methods at 1.1.0
+ - deps: parseurl@~1.1.3
+ * deps: parseurl@~1.1.3
+ - faster parsing of href-only URLs
+ * deps: serve-static@~1.3.1
+ - deps: parseurl@~1.1.3
+
+2.22.0 / 2014-07-03
+===================
+
+ * deps: csurf@~1.3.0
+ - Fix `cookie.signed` option to actually sign cookie
+ * deps: express-session@~1.6.1
+ - Fix `res.end` patch to return correct value
+ - Fix `res.end` patch to handle multiple `res.end` calls
+ - Reject cookies with missing signatures
+ * deps: multiparty at 3.3.0
+ - Always emit close after all parts ended
+ - Fix callback hang in node.js 0.8 on errors
+ * deps: serve-static@~1.3.0
+ - Accept string for `maxAge` (converted by `ms`)
+ - Add `setHeaders` option
+ - Include HTML link in redirect response
+ - deps: send at 0.5.0
+
+2.21.1 / 2014-06-26
+===================
+
+ * deps: cookie-parser at 1.3.2
+ - deps: cookie-signature at 1.0.4
+ * deps: cookie-signature at 1.0.4
+ - fix for timing attacks
+ * deps: express-session@~1.5.2
+ - deps: cookie-signature at 1.0.4
+ * deps: type-is@~1.3.2
+ - more mime types
+
+2.21.0 / 2014-06-20
+===================
+
+ * deprecate `connect(middleware)` -- use `app.use(middleware)` instead
+ * deprecate `connect.createServer()` -- use `connect()` instead
+ * fix `res.setHeader()` patch to work with get -> append -> set pattern
+ * deps: compression@~1.0.8
+ * deps: errorhandler@~1.1.1
+ * deps: express-session@~1.5.0
+ - Deprecate integration with `cookie-parser` middleware
+ - Deprecate looking for secret in `req.secret`
+ - Directly read cookies; `cookie-parser` no longer required
+ - Directly set cookies; `res.cookie` no longer required
+ - Generate session IDs with `uid-safe`, faster and even less collisions
+ * deps: serve-index@~1.1.3
+
+2.20.2 / 2014-06-19
+===================
+
+ * deps: body-parser at 1.4.3
+ - deps: type-is at 1.3.1
+
+2.20.1 / 2014-06-19
+===================
+
+ * deps: type-is at 1.3.1
+ - fix global variable leak
+
+2.20.0 / 2014-06-19
+===================
+
+ * deprecate `verify` option to `json` -- use `body-parser` npm module instead
+ * deprecate `verify` option to `urlencoded` -- use `body-parser` npm module instead
+ * deprecate things with `depd` module
+ * use `finalhandler` for final response handling
+ * use `media-typer` to parse `content-type` for charset
+ * deps: body-parser at 1.4.2
+ - check accepted charset in content-type (accepts utf-8)
+ - check accepted encoding in content-encoding (accepts identity)
+ - deprecate `urlencoded()` without provided `extended` option
+ - lazy-load urlencoded parsers
+ - support gzip and deflate bodies
+ - set `inflate: false` to turn off
+ - deps: raw-body at 1.2.2
+ - deps: type-is at 1.3.0
+ - Support all encodings from `iconv-lite`
+ * deps: connect-timeout at 1.1.1
+ - deps: debug at 1.0.2
+ * deps: cookie-parser at 1.3.1
+ - export parsing functions
+ - `req.cookies` and `req.signedCookies` are now plain objects
+ - slightly faster parsing of many cookies
+ * deps: csurf at 1.2.2
+ * deps: errorhandler at 1.1.0
+ - Display error on console formatted like `throw`
+ - Escape HTML in stack trace
+ - Escape HTML in title
+ - Fix up edge cases with error sent in response
+ - Set `X-Content-Type-Options: nosniff` header
+ - Use accepts for negotiation
+ * deps: express-session at 1.4.0
+ - Add `genid` option to generate custom session IDs
+ - Add `saveUninitialized` option to control saving uninitialized sessions
+ - Add `unset` option to control unsetting `req.session`
+ - Generate session IDs with `rand-token` by default; reduce collisions
+ - Integrate with express "trust proxy" by default
+ - deps: buffer-crc32 at 0.2.3
+ - deps: debug at 1.0.2
+ * deps: multiparty at 3.2.9
+ * deps: serve-index at 1.1.2
+ - deps: batch at 0.5.1
+ * deps: type-is at 1.3.0
+ - improve type parsing
+ * deps: vhost at 2.0.0
+ - Accept `RegExp` object for `hostname`
+ - Provide `req.vhost` object
+ - Support IPv6 literal in `Host` header
+
+2.19.6 / 2014-06-11
+===================
+
+ * deps: body-parser at 1.3.1
+ - deps: type-is at 1.2.1
+ * deps: compression at 1.0.7
+ - use vary module for better `Vary` behavior
+ - deps: accepts at 1.0.3
+ - deps: compressible at 1.1.0
+ * deps: debug at 1.0.2
+ * deps: serve-index at 1.1.1
+ - deps: accepts at 1.0.3
+ * deps: serve-static at 1.2.3
+ - Do not throw un-catchable error on file open race condition
+ - deps: send at 0.4.3
+
+2.19.5 / 2014-06-09
+===================
+
+ * deps: csurf at 1.2.1
+ - refactor to use csrf-tokens@~1.0.2
+ * deps: debug at 1.0.1
+ * deps: serve-static at 1.2.2
+ - fix "event emitter leak" warnings
+ - deps: send at 0.4.2
+ * deps: type-is at 1.2.1
+ - Switch dependency from `mime` to `mime-types at 1.0.0`
+
+2.19.4 / 2014-06-05
+===================
+
+ * deps: errorhandler at 1.0.2
+ - Pass on errors from reading error files
+ * deps: method-override at 2.0.2
+ - use vary module for better `Vary` behavior
+ * deps: serve-favicon at 2.0.1
+ - Reduce byte size of `ETag` header
+
+2.19.3 / 2014-06-03
+===================
+
+ * deps: compression at 1.0.6
+ - fix listeners for delayed stream creation
+ - fix regression for certain `stream.pipe(res)` situations
+ - fix regression when negotiation fails
+
+2.19.2 / 2014-06-03
+===================
+
+ * deps: compression at 1.0.4
+ - fix adding `Vary` when value stored as array
+ - fix back-pressure behavior
+ - fix length check for `res.end`
+
+2.19.1 / 2014-06-02
+===================
+
+ * fix deprecated `utils.escape`
+
+2.19.0 / 2014-06-02
+===================
+
+ * deprecate `methodOverride()` -- use `method-override` npm module instead
+ * deps: body-parser at 1.3.0
+ - add `extended` option to urlencoded parser
+ * deps: method-override at 2.0.1
+ - set `Vary` header
+ - deps: methods at 1.0.1
+ * deps: multiparty at 3.2.8
+ * deps: response-time at 2.0.0
+ - add `digits` argument
+ - do not override existing `X-Response-Time` header
+ - timer not subject to clock drift
+ - timer resolution down to nanoseconds
+ * deps: serve-static at 1.2.1
+ - send max-age in Cache-Control in correct format
+ - use `escape-html` for escaping
+ - deps: send at 0.4.1
+
2.18.0 / 2014-05-29
===================
* deps: compression at 1.0.3
- * deps: serve-static at 1.1.0
+ * deps: serve-index at 1.1.0
- Fix content negotiation when no `Accept` header
- Properly support all HTTP methods
- Support vanilla node.js http servers
diff --git a/Readme.md b/Readme.md
index 5131186..fa4b239 100644
--- a/Readme.md
+++ b/Readme.md
@@ -1,22 +1,40 @@
-# Connect [![NPM version](https://badge.fury.io/js/connect.svg)](http://badge.fury.io/js/connect) [![Build Status](https://travis-ci.org/senchalabs/connect.svg?branch=master)](https://travis-ci.org/senchalabs/connect) [![Coverage Status](https://img.shields.io/coveralls/senchalabs/connect.svg)](https://coveralls.io/r/senchalabs/connect)
+# Connect
+
+[![NPM Version][npm-image]][npm-url]
+[![NPM Downloads][downloads-image]][downloads-url]
+[![Build Status][travis-image]][travis-url]
+[![Test Coverage][coveralls-image]][coveralls-url]
+[![Gittip][gittip-image]][gittip-url]
Connect is an extensible HTTP server framework for [node](http://nodejs.org) using "plugins" known as _middleware_.
```js
var connect = require('connect')
- , http = require('http');
+var http = require('http')
var app = connect()
- .use(require('compression')())
- .use(require('cookie-session')({
+
+// gzip/deflate outgoing responses
+var compression = require('compression')
+app.use(compression())
+
+// store session state in browser cookie
+var cookieSession = require('cookie-session')
+app.use(cookieSession({
keys: ['secret1', 'secret2']
- }))
- .use(require('body-parser')())
- .use(function(req, res){
- res.end('Hello from Connect!\n');
- });
+}))
+
+// parse urlencoded request bodies into req.body
+var bodyParser = require('body-parser')
+app.use(bodyParser.urlencoded())
+
+// respond to all requests
+app.use(function(req, res){
+ res.end('Hello from Connect!\n');
+})
-http.createServer(app).listen(3000);
+//create node.js http server and listen on port
+http.createServer(app).listen(3000)
```
## Connect 3.0
@@ -28,7 +46,7 @@ Connect 3.0 is in progress in the `master` branch. The main changes in Connect a
- Node `0.8` is no longer supported
- The website documentation has been removed - view the markdown readmes instead
-If you would like to help maintain these middleware, please contact a [member of the expressjs team](https://github.com/orgs/expressjs/members).
+If you would like to help maintain these middleware, please contact a [member of the expressjs team](https://github.com/orgs/expressjs/people).
## Middleware
@@ -93,4 +111,15 @@ npm test
## License
-View the [LICENSE](https://github.com/senchalabs/connect/blob/master/LICENSE) file.
+[MIT](LICENSE)
+
+[npm-image]: https://img.shields.io/npm/v/connect.svg?style=flat
+[npm-url]: https://npmjs.org/package/connect
+[travis-image]: https://img.shields.io/travis/senchalabs/connect.svg?style=flat
+[travis-url]: https://travis-ci.org/senchalabs/connect
+[coveralls-image]: https://img.shields.io/coveralls/senchalabs/connect.svg?style=flat
+[coveralls-url]: https://coveralls.io/r/senchalabs/connect
+[downloads-image]: https://img.shields.io/npm/dm/connect.svg?style=flat
+[downloads-url]: https://npmjs.org/package/connect
+[gittip-image]: https://img.shields.io/gittip/dougwilson.svg?style=flat
+[gittip-url]: https://www.gittip.com/dougwilson/
diff --git a/lib/proto.js b/lib/proto.js
index d645c7e..bf18809 100644
--- a/lib/proto.js
+++ b/lib/proto.js
@@ -9,8 +9,8 @@
* Module dependencies.
*/
+var finalhandler = require('finalhandler');
var http = require('http');
-var escapehtml = require('escape-html');
var debug = require('debug')('connect:dispatcher');
var parseUrl = require('parseurl');
@@ -33,26 +33,6 @@ var env = process.env.NODE_ENV || 'development';
* be invoked on _/admin_, and _/admin/settings_, however it would
* not be invoked for _/_, or _/posts_.
*
- * Examples:
- *
- * var app = connect();
- * app.use(connect.favicon());
- * app.use(connect.logger());
- * app.use(connect.static(__dirname + '/public'));
- *
- * If we wanted to prefix static files with _/public_, we could
- * "mount" the `static()` middleware:
- *
- * app.use('/public', connect.static(__dirname + '/public'));
- *
- * This api is chainable, so the following is valid:
- *
- * connect()
- * .use(connect.favicon())
- * .use(connect.logger())
- * .use(connect.static(__dirname + '/public'))
- * .listen(3000);
- *
* @param {String|Function|Server} route, callback or server
* @param {Function|Server} callback or server
* @return {Server} for chaining
@@ -109,96 +89,66 @@ app.handle = function(req, res, out) {
, slashAdded = false
, index = 0;
- function next(err) {
- var layer, path, c;
+ // final function handler
+ var done = out || finalhandler(req, res, {
+ env: env,
+ onerror: logerror
+ });
+ // store the original URL
+ req.originalUrl = req.originalUrl || req.url;
+
+ function next(err) {
if (slashAdded) {
req.url = req.url.substr(1);
slashAdded = false;
}
- req.url = protohost + removed + req.url.substr(protohost.length);
- req.originalUrl = req.originalUrl || req.url;
- removed = '';
+ if (removed.length !== 0) {
+ req.url = protohost + removed + req.url.substr(protohost.length);
+ removed = '';
+ }
// next callback
- layer = stack[index++];
+ var layer = stack[index++];
// all done
if (!layer) {
- // delegate to parent
- if (out) return out(err);
-
- // unhandled error
- if (err) {
- // default to 500
- if (res.statusCode < 400) res.statusCode = 500;
- debug('default %s', res.statusCode);
-
- // respect err.status
- if (err.status) res.statusCode = err.status;
-
- // production gets a basic error message
- var msg = 'production' == env
- ? http.STATUS_CODES[res.statusCode]
- : err.stack || err.toString();
- msg = escapehtml(msg).replace(/\n/g, '<br>').replace(/ /g, ' ');
-
- // log to stderr in a non-test env
- if ('test' != env) console.error(err.stack || err.toString());
- if (res.headersSent) return req.socket.destroy();
- res.setHeader('Content-Type', 'text/html');
- res.setHeader('Content-Length', Buffer.byteLength(msg));
- if ('HEAD' == req.method) return res.end();
- res.end(msg + '\n');
- } else if (!res.headersSent) {
- debug('default 404');
- res.statusCode = 404;
- res.setHeader('Content-Type', 'text/html');
- if ('HEAD' == req.method) return res.end();
- res.end('Cannot ' + escapehtml(req.method) + ' ' + escapehtml(req.originalUrl) + '\n');
- }
+ done(err);
return;
}
- try {
- path = parseUrl(req).pathname;
- if (undefined == path) path = '/';
+ // route data
+ var path = parseUrl(req).pathname || '/';
+ var route = layer.route;
- // skip this layer if the route doesn't match.
- if (0 != path.toLowerCase().indexOf(layer.route.toLowerCase())) return next(err);
+ // skip this layer if the route doesn't match
+ if (path.toLowerCase().substr(0, route.length) !== route.toLowerCase()) {
+ return next(err);
+ }
- c = path[layer.route.length];
- if (c && '/' != c && '.' != c) return next(err);
+ // skip if route match does not border "/", ".", or end
+ var c = path[route.length];
+ if (c !== undefined && '/' !== c && '.' !== c) {
+ return next(err);
+ }
- // Call the layer handler
- // Trim off the part of the url that matches the route
- removed = layer.route;
+ // trim off the part of the url that matches the route
+ if (route.length !== 0 && route !== '/') {
+ removed = route;
req.url = protohost + req.url.substr(protohost.length + removed.length);
- // Ensure leading slash
- if (!fqdn && '/' != req.url[0]) {
+ // ensure leading slash
+ if (!fqdn && req.url[0] !== '/') {
req.url = '/' + req.url;
slashAdded = true;
}
-
- debug('%s %s : %s', layer.handle.name || 'anonymous', layer.route, req.originalUrl);
- var arity = layer.handle.length;
- if (err) {
- if (arity === 4) {
- layer.handle(err, req, res, next);
- } else {
- next(err);
- }
- } else if (arity < 4) {
- layer.handle(req, res, next);
- } else {
- next();
- }
- } catch (e) {
- next(e);
}
+
+ // call the layer handle
+ call(layer.handle, route, err, req, res, next);
}
+
next();
};
@@ -232,3 +182,45 @@ app.listen = function(){
var server = http.createServer(this);
return server.listen.apply(server, arguments);
};
+
+/**
+ * Invoke a route handle.
+ *
+ * @api private
+ */
+
+function call(handle, route, err, req, res, next) {
+ var arity = handle.length;
+ var hasError = Boolean(err);
+
+ debug('%s %s : %s', handle.name || '<anonymous>', route, req.originalUrl);
+
+ try {
+ if (hasError && arity === 4) {
+ // error-handling middleware
+ handle(err, req, res, next);
+ return;
+ } else if (!hasError && arity < 4) {
+ // request-handling middleware
+ handle(req, res, next);
+ return;
+ }
+ } catch (e) {
+ // reset the error
+ err = e;
+ }
+
+ // continue
+ next(err);
+}
+
+/**
+ * Log error using console.error.
+ *
+ * @param {Error} err
+ * @api public
+ */
+
+function logerror(err){
+ if (env !== 'test') console.error(err.stack || err.toString());
+}
diff --git a/package.json b/package.json
index e63482d..e1c4bfb 100644
--- a/package.json
+++ b/package.json
@@ -1,21 +1,12 @@
{
"name": "connect",
- "version": "3.0.0",
"description": "High performance middleware framework",
+ "version": "3.2.0",
"author": "TJ Holowaychuk <tj at vision-media.ca> (http://tjholowaychuk.com)",
"contributors": [
- {
- "name": "Douglas Christopher Wilson",
- "email": "doug at somethingdoug.com"
- },
- {
- "name": "Jonathan Ong",
- "email": "me at jongleberry.com"
- },
- {
- "name": "Tim Caswell",
- "email": "tim at creationix.com"
- }
+ "Douglas Christopher Wilson <doug at somethingdoug.com>",
+ "Jonathan Ong <me at jongleberry.com>",
+ "Tim Caswell <tim at creationix.com>"
],
"keywords": [
"framework",
@@ -24,26 +15,26 @@
"connect",
"rack"
],
- "repository": "git://github.com/senchalabs/connect.git",
+ "repository": "senchalabs/connect",
"dependencies": {
- "debug": "0.8.1",
- "parseurl": "1.0.1",
- "escape-html": "1.0.1",
+ "debug": "~2.0.0",
+ "finalhandler": "0.2.0",
+ "parseurl": "~1.3.0",
"utils-merge": "1.0.0"
},
"devDependencies": {
- "istanbul": "0.2.10",
- "mocha": "~1.19.0",
- "should": "~3.3.1",
- "supertest": "~0.12.0"
+ "istanbul": "0.3.2",
+ "mocha": "~1.21.4",
+ "should": "~4.0.0",
+ "supertest": "~0.13.0"
},
"license": "MIT",
"engines": {
"node": ">= 0.10.0"
},
"scripts": {
- "test": "mocha --require test/support/env --reporter dot",
- "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --require test/support/env --reporter dot",
- "test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --require test/support/env --reporter spec"
+ "test": "mocha --require test/support/env --reporter spec --bail --check-leaks test/",
+ "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --require test/support/env --reporter dot --check-leaks test/",
+ "test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --require test/support/env --reporter spec --check-leaks test/"
}
}
diff --git a/test/mounting.js b/test/mounting.js
index 8da6184..3bd14b1 100644
--- a/test/mounting.js
+++ b/test/mounting.js
@@ -11,6 +11,116 @@ describe('app.use()', function(){
app = connect();
});
+ it('should match all paths with "/"', function (done) {
+ app.use('/', function (req, res) {
+ res.end(req.url);
+ });
+
+ request(app)
+ .get('/blog')
+ .expect(200, '/blog', done);
+ });
+
+ it('should match full path', function (done) {
+ app.use('/blog', function (req, res) {
+ res.end(req.url);
+ });
+
+ request(app)
+ .get('/blog')
+ .expect(200, '/', done);
+ });
+
+ it('should match left-side of path', function (done) {
+ app.use('/blog', function (req, res) {
+ res.end(req.url);
+ });
+
+ request(app)
+ .get('/blog/article/1')
+ .expect(200, '/article/1', done);
+ });
+
+ it('should not match shorter path', function (done) {
+ app.use('/blog-o-rama', function (req, res) {
+ res.end(req.url);
+ });
+
+ request(app)
+ .get('/blog')
+ .expect(404, done);
+ });
+
+ it('should not end match in middle of component', function (done) {
+ app.use('/blog', function (req, res) {
+ res.end(req.url);
+ });
+
+ request(app)
+ .get('/blog-o-rama/article/1')
+ .expect(404, done);
+ });
+
+ it('should be case insensitive (lower-case route, mixed-case request)', function(done){
+ var blog = http.createServer(function(req, res){
+ req.url.should.equal('/');
+ res.end('blog');
+ });
+
+ app.use('/blog', blog);
+
+ request(app)
+ .get('/BLog')
+ .expect('blog', done);
+ });
+
+ it('should be case insensitive (mixed-case route, lower-case request)', function(done){
+ var blog = http.createServer(function(req, res){
+ req.url.should.equal('/');
+ res.end('blog');
+ });
+
+ app.use('/BLog', blog);
+
+ request(app)
+ .get('/blog')
+ .expect('blog', done);
+ });
+
+ it('should be case insensitive (mixed-case route, mixed-case request)', function(done){
+ var blog = http.createServer(function(req, res){
+ req.url.should.equal('/');
+ res.end('blog');
+ });
+
+ app.use('/BLog', blog);
+
+ request(app)
+ .get('/blOG')
+ .expect('blog', done);
+ });
+
+ it('should ignore fn.arity > 4', function(done){
+ var invoked = [];
+
+ app.use(function(req, res, next, _a, _b){
+ invoked.push(0)
+ next();
+ });
+ app.use(function(req, res, next){
+ invoked.push(1)
+ next(new Error('err'));
+ });
+ app.use(function(err, req, res, next){
+ invoked.push(2);
+ res.end(invoked.join(','));
+ });
+
+ request(app)
+ .get('/')
+ .expect(200, '1,2', done);
+ });
+
describe('with a connect app', function(){
it('should mount', function(done){
var blog = connect();
@@ -169,64 +279,4 @@ describe('app.use()', function(){
.end(function(){});
})
})
-
- it('should be case insensitive (lower-case route, mixed-case request)', function(done){
- var blog = http.createServer(function(req, res){
- req.url.should.equal('/');
- res.end('blog');
- });
-
- app.use('/blog', blog);
-
- request(app)
- .get('/BLog')
- .expect('blog', done);
- });
-
- it('should be case insensitive (mixed-case route, lower-case request)', function(done){
- var blog = http.createServer(function(req, res){
- req.url.should.equal('/');
- res.end('blog');
- });
-
- app.use('/BLog', blog);
-
- request(app)
- .get('/blog')
- .expect('blog', done);
- });
-
- it('should be case insensitive (mixed-case route, mixed-case request)', function(done){
- var blog = http.createServer(function(req, res){
- req.url.should.equal('/');
- res.end('blog');
- });
-
- app.use('/BLog', blog);
-
- request(app)
- .get('/blOG')
- .expect('blog', done);
- });
-
- it('should ignore fn.arity > 4', function(done){
- var invoked = [];
-
- app.use(function(req, res, next, _a, _b){
- invoked.push(0)
- next();
- });
- app.use(function(req, res, next){
- invoked.push(1)
- next(new Error('err'));
- });
- app.use(function(err, req, res, next){
- invoked.push(2);
- res.end(invoked.join(','));
- });
-
- request(app)
- .get('/')
- .expect(200, '1,2', done);
- });
});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-connect.git
More information about the Pkg-javascript-commits
mailing list