package/.npmignore000644 000765 000024 0000000072 11736457113012535 0ustar00000000 000000 .git* docs/ examples/ support/ test/ testing.js .DS_Store package/bin/000755 000765 000024 0000000000 11736457244011314 5ustar00000000 000000 package/bin/express000755 000765 000024 0000020351 11736457113012727 0ustar00000000 000000 #!/usr/bin/env node /** * Module dependencies. */ var fs = require('fs') , os = require('os') , exec = require('child_process').exec , mkdirp = require('mkdirp'); /** * Framework version. */ var version = '2.5.8'; /** * Add session support. */ var sessions = false; /** * CSS engine to utilize. */ var cssEngine; /** * End-of-line code. */ var eol = os.platform ? ('win32' == os.platform() ? '\r\n' : '\n') : '\n'; /** * Template engine to utilize. */ var templateEngine = 'jade'; /** * Usage documentation. */ var usage = '' + '\n' + ' Usage: express [options] [path]\n' + '\n' + ' Options:\n' + ' -s, --sessions add session support\n' + ' -t, --template add template support (jade|ejs). default=jade\n' + ' -c, --css add stylesheet support (stylus). default=plain css\n' + ' -v, --version output framework version\n' + ' -h, --help output help information\n' ; /** * Routes index template. */ var index = [ '' , '/*' , ' * GET home page.' , ' */' , '' , 'exports.index = function(req, res){' , ' res.render(\'index\', { title: \'Express\' })' , '};' ].join(eol); /** * Jade layout template. */ var jadeLayout = [ '!!!' , 'html' , ' head' , ' title= title' , ' link(rel=\'stylesheet\', href=\'/stylesheets/style.css\')' , ' body!= body' ].join(eol); /** * Jade index template. */ var jadeIndex = [ 'h1= title' , 'p Welcome to #{title}' ].join(eol); /** * EJS layout template. */ var ejsLayout = [ '' , '' , ' ' , ' <%= title %>' , ' ' , ' ' , ' ' , ' <%- body %>' , ' ' , '' ].join(eol); /** * EJS index template. */ var ejsIndex = [ '

<%= title %>

' , '

Welcome to <%= title %>

' ].join(eol); /** * Default css template. */ var css = [ 'body {' , ' padding: 50px;' , ' font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;' , '}' , '' , 'a {' , ' color: #00B7FF;' , '}' ].join(eol); /** * Default stylus template. */ var stylus = [ 'body' , ' padding: 50px' , ' font: 14px "Lucida Grande", Helvetica, Arial, sans-serif' , 'a' , ' color: #00B7FF' ].join(eol); /** * App template. */ var app = [ '' , '/**' , ' * Module dependencies.' , ' */' , '' , 'var express = require(\'express\')' , ' , routes = require(\'./routes\');' , '' , 'var app = module.exports = express.createServer();' , '' , '// Configuration' , '' , 'app.configure(function(){' , ' app.set(\'views\', __dirname + \'/views\');' , ' app.set(\'view engine\', \':TEMPLATE\');' , ' app.use(express.bodyParser());' , ' app.use(express.methodOverride());{sess}{css}' , ' app.use(app.router);' , ' app.use(express.static(__dirname + \'/public\'));' , '});' , '' , 'app.configure(\'development\', function(){' , ' app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));' , '});' , '' , 'app.configure(\'production\', function(){' , ' app.use(express.errorHandler());' , '});' , '' , '// Routes' , '' , 'app.get(\'/\', routes.index);' , '' , 'app.listen(3000, function(){' , ' console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);' , '});' , '' ].join(eol); // Parse arguments var args = process.argv.slice(2) , path = '.'; while (args.length) { var arg = args.shift(); switch (arg) { case '-h': case '--help': abort(usage); break; case '-v': case '--version': abort(version); break; case '-s': case '--session': case '--sessions': sessions = true; break; case '-c': case '--css': args.length ? (cssEngine = args.shift()) : abort('--css requires an argument'); break; case '-t': case '--template': args.length ? (templateEngine = args.shift()) : abort('--template requires an argument'); break; default: path = arg; } } // Generate application (function createApplication(path) { emptyDirectory(path, function(empty){ if (empty) { createApplicationAt(path); } else { confirm('destination is not empty, continue? ', function(ok){ if (ok) { process.stdin.destroy(); createApplicationAt(path); } else { abort('aborting'); } }); } }); })(path); /** * Create application at the given directory `path`. * * @param {String} path */ function createApplicationAt(path) { console.log(); process.on('exit', function(){ console.log(); console.log(' dont forget to install dependencies:'); console.log(' $ cd %s && npm install', path); console.log(); }); mkdir(path, function(){ mkdir(path + '/public'); mkdir(path + '/public/javascripts'); mkdir(path + '/public/images'); mkdir(path + '/public/stylesheets', function(){ switch (cssEngine) { case 'stylus': write(path + '/public/stylesheets/style.styl', stylus); break; default: write(path + '/public/stylesheets/style.css', css); } }); mkdir(path + '/routes', function(){ write(path + '/routes/index.js', index); }); mkdir(path + '/views', function(){ switch (templateEngine) { case 'ejs': write(path + '/views/layout.ejs', ejsLayout); write(path + '/views/index.ejs', ejsIndex); break; case 'jade': write(path + '/views/layout.jade', jadeLayout); write(path + '/views/index.jade', jadeIndex); break; } }); // CSS Engine support switch (cssEngine) { case 'stylus': app = app.replace('{css}', eol + ' app.use(require(\'stylus\').middleware({ src: __dirname + \'/public\' }));'); break; default: app = app.replace('{css}', ''); } // Session support app = app.replace('{sess}', sessions ? eol + ' app.use(express.cookieParser());' + eol + ' app.use(express.session({ secret: \'your secret here\' }));' : ''); // Template support app = app.replace(':TEMPLATE', templateEngine); // package.json var json = '{' + eol; json += ' "name": "application-name"' + eol; json += ' , "version": "0.0.1"' + eol; json += ' , "private": true' + eol; json += ' , "dependencies": {' + eol; json += ' "express": "' + version + '"' + eol; if (cssEngine) json += ' , "' + cssEngine + '": ">= 0.0.1"' + eol; if (templateEngine) json += ' , "' + templateEngine + '": ">= 0.0.1"' + eol; json += ' }' + eol; json += '}'; write(path + '/package.json', json); write(path + '/app.js', app); }); } /** * Check if the given directory `path` is empty. * * @param {String} path * @param {Function} fn */ function emptyDirectory(path, fn) { fs.readdir(path, function(err, files){ if (err && 'ENOENT' != err.code) throw err; fn(!files || !files.length); }); } /** * echo str > path. * * @param {String} path * @param {String} str */ function write(path, str) { fs.writeFile(path, str); console.log(' \x1b[36mcreate\x1b[0m : ' + path); } /** * Prompt confirmation with the given `msg`. * * @param {String} msg * @param {Function} fn */ function confirm(msg, fn) { prompt(msg, function(val){ fn(/^ *y(es)?/i.test(val)); }); } /** * Prompt input with the given `msg` and callback `fn`. * * @param {String} msg * @param {Function} fn */ function prompt(msg, fn) { // prompt if (' ' == msg[msg.length - 1]) { process.stdout.write(msg); } else { console.log(msg); } // stdin process.stdin.setEncoding('ascii'); process.stdin.once('data', function(data){ fn(data); }).resume(); } /** * Mkdir -p. * * @param {String} path * @param {Function} fn */ function mkdir(path, fn) { mkdirp(path, 0755, function(err){ if (err) throw err; console.log(' \033[36mcreate\033[0m : ' + path); fn && fn(); }); } /** * Exit with the given `str`. * * @param {String} str */ function abort(str) { console.error(str); process.exit(1); } package/History.md000644 000765 000024 0000073140 11736457227012535 0ustar00000000 000000 2.5.9/ 2012-04-02 ================== * Added support for PURGE request method [pbuyle] * Fixed `express(1)` generated app `app.address()` before `listening` [mmalecki] 2.5.8 / 2012-02-08 ================== * Update mkdirp dep. Closes #991 2.5.7 / 2012-02-06 ================== * Fixed `app.all` duplicate DELETE requests [mscdex] 2.5.6 / 2012-01-13 ================== * Updated hamljs dev dep. Closes #953 2.5.5 / 2012-01-08 ================== * Fixed: set `filename` on cached templates [matthewleon] 2.5.4 / 2012-01-02 ================== * Fixed `express(1)` eol on 0.4.x. Closes #947 2.5.3 / 2011-12-30 ================== * Fixed `req.is()` when a charset is present 2.5.2 / 2011-12-10 ================== * Fixed: express(1) LF -> CRLF for windows 2.5.1 / 2011-11-17 ================== * Changed: updated connect to 1.8.x * Removed sass.js support from express(1) 2.5.0 / 2011-10-24 ================== * Added ./routes dir for generated app by default * Added npm install reminder to express(1) app gen * Added 0.5.x support * Removed `make test-cov` since it wont work with node 0.5.x * Fixed express(1) public dir for windows. Closes #866 2.4.7 / 2011-10-05 ================== * Added mkdirp to express(1). Closes #795 * Added simple _json-config_ example * Added shorthand for the parsed request's pathname via `req.path` * Changed connect dep to 1.7.x to fix npm issue... * Fixed `res.redirect()` __HEAD__ support. [reported by xerox] * Fixed `req.flash()`, only escape args * Fixed absolute path checking on windows. Closes #829 [reported by andrewpmckenzie] 2.4.6 / 2011-08-22 ================== * Fixed multiple param callback regression. Closes #824 [reported by TroyGoode] 2.4.5 / 2011-08-19 ================== * Added support for routes to handle errors. Closes #809 * Added `app.routes.all()`. Closes #803 * Added "basepath" setting to work in conjunction with reverse proxies etc. * Refactored `Route` to use a single array of callbacks * Added support for multiple callbacks for `app.param()`. Closes #801 Closes #805 * Changed: removed .call(self) for route callbacks * Dependency: `qs >= 0.3.1` * Fixed `res.redirect()` on windows due to `join()` usage. Closes #808 2.4.4 / 2011-08-05 ================== * Fixed `res.header()` intention of a set, even when `undefined` * Fixed `*`, value no longer required * Fixed `res.send(204)` support. Closes #771 2.4.3 / 2011-07-14 ================== * Added docs for `status` option special-case. Closes #739 * Fixed `options.filename`, exposing the view path to template engines 2.4.2. / 2011-07-06 ================== * Revert "removed jsonp stripping" for XSS 2.4.1 / 2011-07-06 ================== * Added `res.json()` JSONP support. Closes #737 * Added _extending-templates_ example. Closes #730 * Added "strict routing" setting for trailing slashes * Added support for multiple envs in `app.configure()` calls. Closes #735 * Changed: `res.send()` using `res.json()` * Changed: when cookie `path === null` don't default it * Changed; default cookie path to "home" setting. Closes #731 * Removed _pids/logs_ creation from express(1) 2.4.0 / 2011-06-28 ================== * Added chainable `res.status(code)` * Added `res.json()`, an explicit version of `res.send(obj)` * Added simple web-service example 2.3.12 / 2011-06-22 ================== * \#express is now on freenode! come join! * Added `req.get(field, param)` * Added links to Japanese documentation, thanks @hideyukisaito! * Added; the `express(1)` generated app outputs the env * Added `content-negotiation` example * Dependency: connect >= 1.5.1 < 2.0.0 * Fixed view layout bug. Closes #720 * Fixed; ignore body on 304. Closes #701 2.3.11 / 2011-06-04 ================== * Added `npm test` * Removed generation of dummy test file from `express(1)` * Fixed; `express(1)` adds express as a dep * Fixed; prune on `prepublish` 2.3.10 / 2011-05-27 ================== * Added `req.route`, exposing the current route * Added _package.json_ generation support to `express(1)` * Fixed call to `app.param()` function for optional params. Closes #682 2.3.9 / 2011-05-25 ================== * Fixed bug-ish with `../' in `res.partial()` calls 2.3.8 / 2011-05-24 ================== * Fixed `app.options()` 2.3.7 / 2011-05-23 ================== * Added route `Collection`, ex: `app.get('/user/:id').remove();` * Added support for `app.param(fn)` to define param logic * Removed `app.param()` support for callback with return value * Removed module.parent check from express(1) generated app. Closes #670 * Refactored router. Closes #639 2.3.6 / 2011-05-20 ================== * Changed; using devDependencies instead of git submodules * Fixed redis session example * Fixed markdown example * Fixed view caching, should not be enabled in development 2.3.5 / 2011-05-20 ================== * Added export `.view` as alias for `.View` 2.3.4 / 2011-05-08 ================== * Added `./examples/say` * Fixed `res.sendfile()` bug preventing the transfer of files with spaces 2.3.3 / 2011-05-03 ================== * Added "case sensitive routes" option. * Changed; split methods supported per rfc [slaskis] * Fixed route-specific middleware when using the same callback function several times 2.3.2 / 2011-04-27 ================== * Fixed view hints 2.3.1 / 2011-04-26 ================== * Added `app.match()` as `app.match.all()` * Added `app.lookup()` as `app.lookup.all()` * Added `app.remove()` for `app.remove.all()` * Added `app.remove.VERB()` * Fixed template caching collision issue. Closes #644 * Moved router over from connect and started refactor 2.3.0 / 2011-04-25 ================== * Added options support to `res.clearCookie()` * Added `res.helpers()` as alias of `res.locals()` * Added; json defaults to UTF-8 with `res.send()`. Closes #632. [Daniel * Dependency `connect >= 1.4.0` * Changed; auto set Content-Type in res.attachement [Aaron Heckmann] * Renamed "cache views" to "view cache". Closes #628 * Fixed caching of views when using several apps. Closes #637 * Fixed gotcha invoking `app.param()` callbacks once per route middleware. Closes #638 * Fixed partial lookup precedence. Closes #631 Shaw] 2.2.2 / 2011-04-12 ================== * Added second callback support for `res.download()` connection errors * Fixed `filename` option passing to template engine 2.2.1 / 2011-04-04 ================== * Added `layout(path)` helper to change the layout within a view. Closes #610 * Fixed `partial()` collection object support. Previously only anything with `.length` would work. When `.length` is present one must still be aware of holes, however now `{ collection: {foo: 'bar'}}` is valid, exposes `keyInCollection` and `keysInCollection`. * Performance improved with better view caching * Removed `request` and `response` locals * Changed; errorHandler page title is now `Express` instead of `Connect` 2.2.0 / 2011-03-30 ================== * Added `app.lookup.VERB()`, ex `app.lookup.put('/user/:id')`. Closes #606 * Added `app.match.VERB()`, ex `app.match.put('/user/12')`. Closes #606 * Added `app.VERB(path)` as alias of `app.lookup.VERB()`. * Dependency `connect >= 1.2.0` 2.1.1 / 2011-03-29 ================== * Added; expose `err.view` object when failing to locate a view * Fixed `res.partial()` call `next(err)` when no callback is given [reported by aheckmann] * Fixed; `res.send(undefined)` responds with 204 [aheckmann] 2.1.0 / 2011-03-24 ================== * Added `/_?` partial lookup support. Closes #447 * Added `request`, `response`, and `app` local variables * Added `settings` local variable, containing the app's settings * Added `req.flash()` exception if `req.session` is not available * Added `res.send(bool)` support (json response) * Fixed stylus example for latest version * Fixed; wrap try/catch around `res.render()` 2.0.0 / 2011-03-17 ================== * Fixed up index view path alternative. * Changed; `res.locals()` without object returns the locals 2.0.0rc3 / 2011-03-17 ================== * Added `res.locals(obj)` to compliment `res.local(key, val)` * Added `res.partial()` callback support * Fixed recursive error reporting issue in `res.render()` 2.0.0rc2 / 2011-03-17 ================== * Changed; `partial()` "locals" are now optional * Fixed `SlowBuffer` support. Closes #584 [reported by tyrda01] * Fixed .filename view engine option [reported by drudge] * Fixed blog example * Fixed `{req,res}.app` reference when mounting [Ben Weaver] 2.0.0rc / 2011-03-14 ================== * Fixed; expose `HTTPSServer` constructor * Fixed express(1) default test charset. Closes #579 [reported by secoif] * Fixed; default charset to utf-8 instead of utf8 for lame IE [reported by NickP] 2.0.0beta3 / 2011-03-09 ================== * Added support for `res.contentType()` literal The original `res.contentType('.json')`, `res.contentType('application/json')`, and `res.contentType('json')` will work now. * Added `res.render()` status option support back * Added charset option for `res.render()` * Added `.charset` support (via connect 1.0.4) * Added view resolution hints when in development and a lookup fails * Added layout lookup support relative to the page view. For example while rendering `./views/user/index.jade` if you create `./views/user/layout.jade` it will be used in favour of the root layout. * Fixed `res.redirect()`. RFC states absolute url [reported by unlink] * Fixed; default `res.send()` string charset to utf8 * Removed `Partial` constructor (not currently used) 2.0.0beta2 / 2011-03-07 ================== * Added res.render() `.locals` support back to aid in migration process * Fixed flash example 2.0.0beta / 2011-03-03 ================== * Added HTTPS support * Added `res.cookie()` maxAge support * Added `req.header()` _Referrer_ / _Referer_ special-case, either works * Added mount support for `res.redirect()`, now respects the mount-point * Added `union()` util, taking place of `merge(clone())` combo * Added stylus support to express(1) generated app * Added secret to session middleware used in examples and generated app * Added `res.local(name, val)` for progressive view locals * Added default param support to `req.param(name, default)` * Added `app.disabled()` and `app.enabled()` * Added `app.register()` support for omitting leading ".", either works * Added `res.partial()`, using the same interface as `partial()` within a view. Closes #539 * Added `app.param()` to map route params to async/sync logic * Added; aliased `app.helpers()` as `app.locals()`. Closes #481 * Added extname with no leading "." support to `res.contentType()` * Added `cache views` setting, defaulting to enabled in "production" env * Added index file partial resolution, eg: partial('user') may try _views/user/index.jade_. * Added `req.accepts()` support for extensions * Changed; `res.download()` and `res.sendfile()` now utilize Connect's static file server `connect.static.send()`. * Changed; replaced `connect.utils.mime()` with npm _mime_ module * Changed; allow `req.query` to be pre-defined (via middleware or other parent * Changed view partial resolution, now relative to parent view * Changed view engine signature. no longer `engine.render(str, options, callback)`, now `engine.compile(str, options) -> Function`, the returned function accepts `fn(locals)`. * Fixed `req.param()` bug returning Array.prototype methods. Closes #552 * Fixed; using `Stream#pipe()` instead of `sys.pump()` in `res.sendfile()` * Fixed; using _qs_ module instead of _querystring_ * Fixed; strip unsafe chars from jsonp callbacks * Removed "stream threshold" setting 1.0.8 / 2011-03-01 ================== * Allow `req.query` to be pre-defined (via middleware or other parent app) * "connect": ">= 0.5.0 < 1.0.0". Closes #547 * Removed the long deprecated __EXPRESS_ENV__ support 1.0.7 / 2011-02-07 ================== * Fixed `render()` setting inheritance. Mounted apps would not inherit "view engine" 1.0.6 / 2011-02-07 ================== * Fixed `view engine` setting bug when period is in dirname 1.0.5 / 2011-02-05 ================== * Added secret to generated app `session()` call 1.0.4 / 2011-02-05 ================== * Added `qs` dependency to _package.json_ * Fixed namespaced `require()`s for latest connect support 1.0.3 / 2011-01-13 ================== * Remove unsafe characters from JSONP callback names [Ryan Grove] 1.0.2 / 2011-01-10 ================== * Removed nested require, using `connect.router` 1.0.1 / 2010-12-29 ================== * Fixed for middleware stacked via `createServer()` previously the `foo` middleware passed to `createServer(foo)` would not have access to Express methods such as `res.send()` or props like `req.query` etc. 1.0.0 / 2010-11-16 ================== * Added; deduce partial object names from the last segment. For example by default `partial('forum/post', postObject)` will give you the _post_ object, providing a meaningful default. * Added http status code string representation to `res.redirect()` body * Added; `res.redirect()` supporting _text/plain_ and _text/html_ via __Accept__. * Added `req.is()` to aid in content negotiation * Added partial local inheritance [suggested by masylum]. Closes #102 providing access to parent template locals. * Added _-s, --session[s]_ flag to express(1) to add session related middleware * Added _--template_ flag to express(1) to specify the template engine to use. * Added _--css_ flag to express(1) to specify the stylesheet engine to use (or just plain css by default). * Added `app.all()` support [thanks aheckmann] * Added partial direct object support. You may now `partial('user', user)` providing the "user" local, vs previously `partial('user', { object: user })`. * Added _route-separation_ example since many people question ways to do this with CommonJS modules. Also view the _blog_ example for an alternative. * Performance; caching view path derived partial object names * Fixed partial local inheritance precedence. [reported by Nick Poulden] Closes #454 * Fixed jsonp support; _text/javascript_ as per mailinglist discussion 1.0.0rc4 / 2010-10-14 ================== * Added _NODE_ENV_ support, _EXPRESS_ENV_ is deprecated and will be removed in 1.0.0 * Added route-middleware support (very helpful, see the [docs](http://expressjs.com/guide.html#Route-Middleware)) * Added _jsonp callback_ setting to enable/disable jsonp autowrapping [Dav Glass] * Added callback query check on response.send to autowrap JSON objects for simple webservice implementations [Dav Glass] * Added `partial()` support for array-like collections. Closes #434 * Added support for swappable querystring parsers * Added session usage docs. Closes #443 * Added dynamic helper caching. Closes #439 [suggested by maritz] * Added authentication example * Added basic Range support to `res.sendfile()` (and `res.download()` etc) * Changed; `express(1)` generated app using 2 spaces instead of 4 * Default env to "development" again [aheckmann] * Removed _context_ option is no more, use "scope" * Fixed; exposing _./support_ libs to examples so they can run without installs * Fixed mvc example 1.0.0rc3 / 2010-09-20 ================== * Added confirmation for `express(1)` app generation. Closes #391 * Added extending of flash formatters via `app.flashFormatters` * Added flash formatter support. Closes #411 * Added streaming support to `res.sendfile()` using `sys.pump()` when >= "stream threshold" * Added _stream threshold_ setting for `res.sendfile()` * Added `res.send()` __HEAD__ support * Added `res.clearCookie()` * Added `res.cookie()` * Added `res.render()` headers option * Added `res.redirect()` response bodies * Added `res.render()` status option support. Closes #425 [thanks aheckmann] * Fixed `res.sendfile()` responding with 403 on malicious path * Fixed `res.download()` bug; when an error occurs remove _Content-Disposition_ * Fixed; mounted apps settings now inherit from parent app [aheckmann] * Fixed; stripping Content-Length / Content-Type when 204 * Fixed `res.send()` 204. Closes #419 * Fixed multiple _Set-Cookie_ headers via `res.header()`. Closes #402 * Fixed bug messing with error handlers when `listenFD()` is called instead of `listen()`. [thanks guillermo] 1.0.0rc2 / 2010-08-17 ================== * Added `app.register()` for template engine mapping. Closes #390 * Added `res.render()` callback support as second argument (no options) * Added callback support to `res.download()` * Added callback support for `res.sendfile()` * Added support for middleware access via `express.middlewareName()` vs `connect.middlewareName()` * Added "partials" setting to docs * Added default expresso tests to `express(1)` generated app. Closes #384 * Fixed `res.sendfile()` error handling, defer via `next()` * Fixed `res.render()` callback when a layout is used [thanks guillermo] * Fixed; `make install` creating ~/.node_libraries when not present * Fixed issue preventing error handlers from being defined anywhere. Closes #387 1.0.0rc / 2010-07-28 ================== * Added mounted hook. Closes #369 * Added connect dependency to _package.json_ * Removed "reload views" setting and support code development env never caches, production always caches. * Removed _param_ in route callbacks, signature is now simply (req, res, next), previously (req, res, params, next). Use _req.params_ for path captures, _req.query_ for GET params. * Fixed "home" setting * Fixed middleware/router precedence issue. Closes #366 * Fixed; _configure()_ callbacks called immediately. Closes #368 1.0.0beta2 / 2010-07-23 ================== * Added more examples * Added; exporting `Server` constructor * Added `Server#helpers()` for view locals * Added `Server#dynamicHelpers()` for dynamic view locals. Closes #349 * Added support for absolute view paths * Added; _home_ setting defaults to `Server#route` for mounted apps. Closes #363 * Added Guillermo Rauch to the contributor list * Added support for "as" for non-collection partials. Closes #341 * Fixed _install.sh_, ensuring _~/.node_libraries_ exists. Closes #362 [thanks jf] * Fixed `res.render()` exceptions, now passed to `next()` when no callback is given [thanks guillermo] * Fixed instanceof `Array` checks, now `Array.isArray()` * Fixed express(1) expansion of public dirs. Closes #348 * Fixed middleware precedence. Closes #345 * Fixed view watcher, now async [thanks aheckmann] 1.0.0beta / 2010-07-15 ================== * Re-write - much faster - much lighter - Check [ExpressJS.com](http://expressjs.com) for migration guide and updated docs 0.14.0 / 2010-06-15 ================== * Utilize relative requires * Added Static bufferSize option [aheckmann] * Fixed caching of view and partial subdirectories [aheckmann] * Fixed mime.type() comments now that ".ext" is not supported * Updated haml submodule * Updated class submodule * Removed bin/express 0.13.0 / 2010-06-01 ================== * Added node v0.1.97 compatibility * Added support for deleting cookies via Request#cookie('key', null) * Updated haml submodule * Fixed not-found page, now using using charset utf-8 * Fixed show-exceptions page, now using using charset utf-8 * Fixed view support due to fs.readFile Buffers * Changed; mime.type() no longer accepts ".type" due to node extname() changes 0.12.0 / 2010-05-22 ================== * Added node v0.1.96 compatibility * Added view `helpers` export which act as additional local variables * Updated haml submodule * Changed ETag; removed inode, modified time only * Fixed LF to CRLF for setting multiple cookies * Fixed cookie complation; values are now urlencoded * Fixed cookies parsing; accepts quoted values and url escaped cookies 0.11.0 / 2010-05-06 ================== * Added support for layouts using different engines - this.render('page.html.haml', { layout: 'super-cool-layout.html.ejs' }) - this.render('page.html.haml', { layout: 'foo' }) // assumes 'foo.html.haml' - this.render('page.html.haml', { layout: false }) // no layout * Updated ext submodule * Updated haml submodule * Fixed EJS partial support by passing along the context. Issue #307 0.10.1 / 2010-05-03 ================== * Fixed binary uploads. 0.10.0 / 2010-04-30 ================== * Added charset support via Request#charset (automatically assigned to 'UTF-8' when respond()'s encoding is set to 'utf8' or 'utf-8'. * Added "encoding" option to Request#render(). Closes #299 * Added "dump exceptions" setting, which is enabled by default. * Added simple ejs template engine support * Added error reponse support for text/plain, application/json. Closes #297 * Added callback function param to Request#error() * Added Request#sendHead() * Added Request#stream() * Added support for Request#respond(304, null) for empty response bodies * Added ETag support to Request#sendfile() * Added options to Request#sendfile(), passed to fs.createReadStream() * Added filename arg to Request#download() * Performance enhanced due to pre-reversing plugins so that plugins.reverse() is not called on each request * Performance enhanced by preventing several calls to toLowerCase() in Router#match() * Changed; Request#sendfile() now streams * Changed; Renamed Request#halt() to Request#respond(). Closes #289 * Changed; Using sys.inspect() instead of JSON.encode() for error output * Changed; run() returns the http.Server instance. Closes #298 * Changed; Defaulting Server#host to null (INADDR_ANY) * Changed; Logger "common" format scale of 0.4f * Removed Logger "request" format * Fixed; Catching ENOENT in view caching, preventing error when "views/partials" is not found * Fixed several issues with http client * Fixed Logger Content-Length output * Fixed bug preventing Opera from retaining the generated session id. Closes #292 0.9.0 / 2010-04-14 ================== * Added DSL level error() route support * Added DSL level notFound() route support * Added Request#error() * Added Request#notFound() * Added Request#render() callback function. Closes #258 * Added "max upload size" setting * Added "magic" variables to collection partials (\_\_index\_\_, \_\_length\_\_, \_\_isFirst\_\_, \_\_isLast\_\_). Closes #254 * Added [haml.js](http://github.com/visionmedia/haml.js) submodule; removed haml-js * Added callback function support to Request#halt() as 3rd/4th arg * Added preprocessing of route param wildcards using param(). Closes #251 * Added view partial support (with collections etc) * Fixed bug preventing falsey params (such as ?page=0). Closes #286 * Fixed setting of multiple cookies. Closes #199 * Changed; view naming convention is now NAME.TYPE.ENGINE (for example page.html.haml) * Changed; session cookie is now httpOnly * Changed; Request is no longer global * Changed; Event is no longer global * Changed; "sys" module is no longer global * Changed; moved Request#download to Static plugin where it belongs * Changed; Request instance created before body parsing. Closes #262 * Changed; Pre-caching views in memory when "cache view contents" is enabled. Closes #253 * Changed; Pre-caching view partials in memory when "cache view partials" is enabled * Updated support to node --version 0.1.90 * Updated dependencies * Removed set("session cookie") in favour of use(Session, { cookie: { ... }}) * Removed utils.mixin(); use Object#mergeDeep() 0.8.0 / 2010-03-19 ================== * Added coffeescript example app. Closes #242 * Changed; cache api now async friendly. Closes #240 * Removed deprecated 'express/static' support. Use 'express/plugins/static' 0.7.6 / 2010-03-19 ================== * Added Request#isXHR. Closes #229 * Added `make install` (for the executable) * Added `express` executable for setting up simple app templates * Added "GET /public/*" to Static plugin, defaulting to /public * Added Static plugin * Fixed; Request#render() only calls cache.get() once * Fixed; Namespacing View caches with "view:" * Fixed; Namespacing Static caches with "static:" * Fixed; Both example apps now use the Static plugin * Fixed set("views"). Closes #239 * Fixed missing space for combined log format * Deprecated Request#sendfile() and 'express/static' * Removed Server#running 0.7.5 / 2010-03-16 ================== * Added Request#flash() support without args, now returns all flashes * Updated ext submodule 0.7.4 / 2010-03-16 ================== * Fixed session reaper * Changed; class.js replacing js-oo Class implementation (quite a bit faster, no browser cruft) 0.7.3 / 2010-03-16 ================== * Added package.json * Fixed requiring of haml / sass due to kiwi removal 0.7.2 / 2010-03-16 ================== * Fixed GIT submodules (HAH!) 0.7.1 / 2010-03-16 ================== * Changed; Express now using submodules again until a PM is adopted * Changed; chat example using millisecond conversions from ext 0.7.0 / 2010-03-15 ================== * Added Request#pass() support (finds the next matching route, or the given path) * Added Logger plugin (default "common" format replaces CommonLogger) * Removed Profiler plugin * Removed CommonLogger plugin 0.6.0 / 2010-03-11 ================== * Added seed.yml for kiwi package management support * Added HTTP client query string support when method is GET. Closes #205 * Added support for arbitrary view engines. For example "foo.engine.html" will now require('engine'), the exports from this module are cached after the first require(). * Added async plugin support * Removed usage of RESTful route funcs as http client get() etc, use http.get() and friends * Removed custom exceptions 0.5.0 / 2010-03-10 ================== * Added ext dependency (library of js extensions) * Removed extname() / basename() utils. Use path module * Removed toArray() util. Use arguments.values * Removed escapeRegexp() util. Use RegExp.escape() * Removed process.mixin() dependency. Use utils.mixin() * Removed Collection * Removed ElementCollection * Shameless self promotion of ebook "Advanced JavaScript" (http://dev-mag.com) ;) 0.4.0 / 2010-02-11 ================== * Added flash() example to sample upload app * Added high level restful http client module (express/http) * Changed; RESTful route functions double as HTTP clients. Closes #69 * Changed; throwing error when routes are added at runtime * Changed; defaulting render() context to the current Request. Closes #197 * Updated haml submodule 0.3.0 / 2010-02-11 ================== * Updated haml / sass submodules. Closes #200 * Added flash message support. Closes #64 * Added accepts() now allows multiple args. fixes #117 * Added support for plugins to halt. Closes #189 * Added alternate layout support. Closes #119 * Removed Route#run(). Closes #188 * Fixed broken specs due to use(Cookie) missing 0.2.1 / 2010-02-05 ================== * Added "plot" format option for Profiler (for gnuplot processing) * Added request number to Profiler plugin * Fixed binary encoding for multi-part file uploads, was previously defaulting to UTF8 * Fixed issue with routes not firing when not files are present. Closes #184 * Fixed process.Promise -> events.Promise 0.2.0 / 2010-02-03 ================== * Added parseParam() support for name[] etc. (allows for file inputs with "multiple" attr) Closes #180 * Added Both Cache and Session option "reapInterval" may be "reapEvery". Closes #174 * Added expiration support to cache api with reaper. Closes #133 * Added cache Store.Memory#reap() * Added Cache; cache api now uses first class Cache instances * Added abstract session Store. Closes #172 * Changed; cache Memory.Store#get() utilizing Collection * Renamed MemoryStore -> Store.Memory * Fixed use() of the same plugin several time will always use latest options. Closes #176 0.1.0 / 2010-02-03 ================== * Changed; Hooks (before / after) pass request as arg as well as evaluated in their context * Updated node support to 0.1.27 Closes #169 * Updated dirname(__filename) -> __dirname * Updated libxmljs support to v0.2.0 * Added session support with memory store / reaping * Added quick uid() helper * Added multi-part upload support * Added Sass.js support / submodule * Added production env caching view contents and static files * Added static file caching. Closes #136 * Added cache plugin with memory stores * Added support to StaticFile so that it works with non-textual files. * Removed dirname() helper * Removed several globals (now their modules must be required) 0.0.2 / 2010-01-10 ================== * Added view benchmarks; currently haml vs ejs * Added Request#attachment() specs. Closes #116 * Added use of node's parseQuery() util. Closes #123 * Added `make init` for submodules * Updated Haml * Updated sample chat app to show messages on load * Updated libxmljs parseString -> parseHtmlString * Fixed `make init` to work with older versions of git * Fixed specs can now run independant specs for those who cant build deps. Closes #127 * Fixed issues introduced by the node url module changes. Closes 126. * Fixed two assertions failing due to Collection#keys() returning strings * Fixed faulty Collection#toArray() spec due to keys() returning strings * Fixed `make test` now builds libxmljs.node before testing 0.0.1 / 2010-01-03 ================== * Initial release package/index.js000644 000765 000024 0000000053 11736457113012202 0ustar00000000 000000 module.exports = require('./lib/express');package/lib/000755 000765 000024 0000000000 11736457244011312 5ustar00000000 000000 package/lib/express.js000644 000765 000024 0000002460 11736457140013336 0ustar00000000 000000 /*! * Express * Copyright(c) 2010 TJ Holowaychuk * MIT Licensed */ /** * Module dependencies. */ var connect = require('connect') , HTTPSServer = require('./https') , HTTPServer = require('./http') , Route = require('./router/route') /** * Re-export connect auto-loaders. * * This prevents the need to `require('connect')` in order * to access core middleware, so for example `express.logger()` instead * of `require('connect').logger()`. */ var exports = module.exports = connect.middleware; /** * Framework version. */ exports.version = '2.5.9'; /** * Shortcut for `new Server(...)`. * * @param {Function} ... * @return {Server} * @api public */ exports.createServer = function(options){ if ('object' == typeof options) { return new HTTPSServer(options, Array.prototype.slice.call(arguments, 1)); } else { return new HTTPServer(Array.prototype.slice.call(arguments)); } }; /** * Expose constructors. */ exports.HTTPServer = HTTPServer; exports.HTTPSServer = HTTPSServer; exports.Route = Route; /** * View extensions. */ exports.View = exports.view = require('./view'); /** * Response extensions. */ require('./response'); /** * Request extensions. */ require('./request'); // Error handler title exports.errorHandler.title = 'Express'; package/lib/http.js000644 000765 000024 0000030257 11736457113012631 0ustar00000000 000000 /*! * Express - HTTPServer * Copyright(c) 2010 TJ Holowaychuk * MIT Licensed */ /** * Module dependencies. */ var qs = require('qs') , connect = require('connect') , router = require('./router') , Router = require('./router') , view = require('./view') , toArray = require('./utils').toArray , methods = router.methods.concat('del', 'all') , url = require('url') , utils = connect.utils; /** * Expose `HTTPServer`. */ exports = module.exports = HTTPServer; /** * Server proto. */ var app = HTTPServer.prototype; /** * Initialize a new `HTTPServer` with optional `middleware`. * * @param {Array} middleware * @api public */ function HTTPServer(middleware){ connect.HTTPServer.call(this, []); this.init(middleware); }; /** * Inherit from `connect.HTTPServer`. */ app.__proto__ = connect.HTTPServer.prototype; /** * Initialize the server. * * @param {Array} middleware * @api private */ app.init = function(middleware){ var self = this; this.cache = {}; this.settings = {}; this.redirects = {}; this.isCallbacks = {}; this._locals = {}; this.dynamicViewHelpers = {}; this.errorHandlers = []; this.set('env', process.env.NODE_ENV || 'development'); // expose objects to each other this.use(function(req, res, next){ req.query = req.query || {}; res.setHeader('X-Powered-By', 'Express'); req.app = res.app = self; req.res = res; res.req = req; req.next = next; // assign req.query if (req.url.indexOf('?') > 0) { var query = url.parse(req.url).query; req.query = qs.parse(query); } next(); }); // apply middleware if (middleware) middleware.forEach(self.use.bind(self)); // router this.routes = new Router(this); this.__defineGetter__('router', function(){ this.__usedRouter = true; return self.routes.middleware; }); // default locals this.locals({ settings: this.settings , app: this }); // default development configuration this.configure('development', function(){ this.enable('hints'); }); // default production configuration this.configure('production', function(){ this.enable('view cache'); }); // register error handlers on "listening" // so that they disregard definition position. this.on('listening', this.registerErrorHandlers.bind(this)); // route manipulation methods methods.forEach(function(method){ self.lookup[method] = function(path){ return self.routes.lookup(method, path); }; self.match[method] = function(path){ return self.routes.match(method, path); }; self.remove[method] = function(path){ return self.routes.lookup(method, path).remove(); }; }); // del -> delete self.lookup.del = self.lookup.delete; self.match.del = self.match.delete; self.remove.del = self.remove.delete; }; /** * Remove routes matching the given `path`. * * @param {Route} path * @return {Boolean} * @api public */ app.remove = function(path){ return this.routes.lookup('all', path).remove(); }; /** * Lookup routes defined with a path * equivalent to `path`. * * @param {Stirng} path * @return {Array} * @api public */ app.lookup = function(path){ return this.routes.lookup('all', path); }; /** * Lookup routes matching the given `url`. * * @param {Stirng} url * @return {Array} * @api public */ app.match = function(url){ return this.routes.match('all', url); }; /** * When using the vhost() middleware register error handlers. */ app.onvhost = function(){ this.registerErrorHandlers(); }; /** * Register error handlers. * * @return {Server} for chaining * @api public */ app.registerErrorHandlers = function(){ this.errorHandlers.forEach(function(fn){ this.use(function(err, req, res, next){ fn.apply(this, arguments); }); }, this); return this; }; /** * Proxy `connect.HTTPServer#use()` to apply settings to * mounted applications. * * @param {String|Function|Server} route * @param {Function|Server} middleware * @return {Server} for chaining * @api public */ app.use = function(route, middleware){ var app, base, handle; if ('string' != typeof route) { middleware = route, route = '/'; } // express app if (middleware.handle && middleware.set) app = middleware; // restore .app property on req and res if (app) { app.route = route; middleware = function(req, res, next) { var orig = req.app; app.handle(req, res, function(err){ req.app = res.app = orig; next(err); }); }; } connect.HTTPServer.prototype.use.call(this, route, middleware); // mounted an app, invoke the hook // and adjust some settings if (app) { base = this.set('basepath') || this.route; if ('/' == base) base = ''; base = base + (app.set('basepath') || app.route); app.set('basepath', base); app.parent = this; if (app.__mounted) app.__mounted.call(app, this); } return this; }; /** * Assign a callback `fn` which is called * when this `Server` is passed to `Server#use()`. * * Examples: * * var app = express.createServer() * , blog = express.createServer(); * * blog.mounted(function(parent){ * // parent is app * // "this" is blog * }); * * app.use(blog); * * @param {Function} fn * @return {Server} for chaining * @api public */ app.mounted = function(fn){ this.__mounted = fn; return this; }; /** * See: view.register. * * @return {Server} for chaining * @api public */ app.register = function(){ view.register.apply(this, arguments); return this; }; /** * Register the given view helpers `obj`. This method * can be called several times to apply additional helpers. * * @param {Object} obj * @return {Server} for chaining * @api public */ app.helpers = app.locals = function(obj){ utils.merge(this._locals, obj); return this; }; /** * Register the given dynamic view helpers `obj`. This method * can be called several times to apply additional helpers. * * @param {Object} obj * @return {Server} for chaining * @api public */ app.dynamicHelpers = function(obj){ utils.merge(this.dynamicViewHelpers, obj); return this; }; /** * Map the given param placeholder `name`(s) to the given callback(s). * * Param mapping is used to provide pre-conditions to routes * which us normalized placeholders. This callback has the same * signature as regular middleware, for example below when ":userId" * is used this function will be invoked in an attempt to load the user. * * app.param('userId', function(req, res, next, id){ * User.find(id, function(err, user){ * if (err) { * next(err); * } else if (user) { * req.user = user; * next(); * } else { * next(new Error('failed to load user')); * } * }); * }); * * Passing a single function allows you to map logic * to the values passed to `app.param()`, for example * this is useful to provide coercion support in a concise manner. * * The following example maps regular expressions to param values * ensuring that they match, otherwise passing control to the next * route: * * app.param(function(name, regexp){ * if (regexp instanceof RegExp) { * return function(req, res, next, val){ * var captures; * if (captures = regexp.exec(String(val))) { * req.params[name] = captures; * next(); * } else { * next('route'); * } * } * } * }); * * We can now use it as shown below, where "/commit/:commit" expects * that the value for ":commit" is at 5 or more digits. The capture * groups are then available as `req.params.commit` as we defined * in the function above. * * app.param('commit', /^\d{5,}$/); * * For more of this useful functionality take a look * at [express-params](http://github.com/visionmedia/express-params). * * @param {String|Array|Function} name * @param {Function} fn * @return {Server} for chaining * @api public */ app.param = function(name, fn){ var self = this , fns = [].slice.call(arguments, 1); // array if (Array.isArray(name)) { name.forEach(function(name){ fns.forEach(function(fn){ self.param(name, fn); }); }); // param logic } else if ('function' == typeof name) { this.routes.param(name); // single } else { if (':' == name[0]) name = name.substr(1); fns.forEach(function(fn){ self.routes.param(name, fn); }); } return this; }; /** * Assign a custom exception handler callback `fn`. * These handlers are always _last_ in the middleware stack. * * @param {Function} fn * @return {Server} for chaining * @api public */ app.error = function(fn){ this.errorHandlers.push(fn); return this; }; /** * Register the given callback `fn` for the given `type`. * * @param {String} type * @param {Function} fn * @return {Server} for chaining * @api public */ app.is = function(type, fn){ if (!fn) return this.isCallbacks[type]; this.isCallbacks[type] = fn; return this; }; /** * Assign `setting` to `val`, or return `setting`'s value. * Mounted servers inherit their parent server's settings. * * @param {String} setting * @param {String} val * @return {Server|Mixed} for chaining, or the setting value * @api public */ app.set = function(setting, val){ if (val === undefined) { if (this.settings.hasOwnProperty(setting)) { return this.settings[setting]; } else if (this.parent) { return this.parent.set(setting); } } else { this.settings[setting] = val; return this; } }; /** * Check if `setting` is enabled. * * @param {String} setting * @return {Boolean} * @api public */ app.enabled = function(setting){ return !!this.set(setting); }; /** * Check if `setting` is disabled. * * @param {String} setting * @return {Boolean} * @api public */ app.disabled = function(setting){ return !this.set(setting); }; /** * Enable `setting`. * * @param {String} setting * @return {Server} for chaining * @api public */ app.enable = function(setting){ return this.set(setting, true); }; /** * Disable `setting`. * * @param {String} setting * @return {Server} for chaining * @api public */ app.disable = function(setting){ return this.set(setting, false); }; /** * Redirect `key` to `url`. * * @param {String} key * @param {String} url * @return {Server} for chaining * @api public */ app.redirect = function(key, url){ this.redirects[key] = url; return this; }; /** * Configure callback for zero or more envs, * when no env is specified that callback will * be invoked for all environments. Any combination * can be used multiple times, in any order desired. * * Examples: * * app.configure(function(){ * // executed for all envs * }); * * app.configure('stage', function(){ * // executed staging env * }); * * app.configure('stage', 'production', function(){ * // executed for stage and production * }); * * @param {String} env... * @param {Function} fn * @return {Server} for chaining * @api public */ app.configure = function(env, fn){ var envs = 'all' , args = toArray(arguments); fn = args.pop(); if (args.length) envs = args; if ('all' == envs || ~envs.indexOf(this.settings.env)) fn.call(this); return this; }; /** * Delegate `.VERB(...)` calls to `.route(VERB, ...)`. */ methods.forEach(function(method){ app[method] = function(path){ if (1 == arguments.length) return this.routes.lookup(method, path); var args = [method].concat(toArray(arguments)); if (!this.__usedRouter) this.use(this.router); return this.routes._route.apply(this.routes, args); } }); /** * Special-cased "all" method, applying the given route `path`, * middleware, and callback to _every_ HTTP method. * * @param {String} path * @param {Function} ... * @return {Server} for chaining * @api public */ app.all = function(path){ var args = arguments; if (1 == args.length) return this.routes.lookup('all', path); methods.forEach(function(method){ if ('all' == method || 'del' == method) return; app[method].apply(this, args); }, this); return this; }; // del -> delete alias app.del = app.delete; package/lib/https.js000644 000765 000024 0000001607 11736457113013011 0ustar00000000 000000 /*! * Express - HTTPSServer * Copyright(c) 2010 TJ Holowaychuk * MIT Licensed */ /** * Module dependencies. */ var connect = require('connect') , HTTPServer = require('./http') , https = require('https'); /** * Expose `HTTPSServer`. */ exports = module.exports = HTTPSServer; /** * Server proto. */ var app = HTTPSServer.prototype; /** * Initialize a new `HTTPSServer` with the * given `options`, and optional `middleware`. * * @param {Object} options * @param {Array} middleware * @api public */ function HTTPSServer(options, middleware){ connect.HTTPSServer.call(this, options, []); this.init(middleware); }; /** * Inherit from `connect.HTTPSServer`. */ app.__proto__ = connect.HTTPSServer.prototype; // mixin HTTPServer methods Object.keys(HTTPServer.prototype).forEach(function(method){ app[method] = HTTPServer.prototype[method]; }); package/lib/request.js000644 000765 000024 0000017425 11736457113013344 0ustar00000000 000000 /*! * Express - request * Copyright(c) 2010 TJ Holowaychuk * MIT Licensed */ /** * Module dependencies. */ var http = require('http') , req = http.IncomingMessage.prototype , utils = require('./utils') , parse = require('url').parse , mime = require('mime'); /** * Default flash formatters. * * @type Object */ var flashFormatters = exports.flashFormatters = { s: function(val){ return String(val); } }; /** * Return request header or optional default. * * The `Referrer` header field is special-cased, * both `Referrer` and `Referer` will yield are * interchangeable. * * Examples: * * req.header('Content-Type'); * // => "text/plain" * * req.header('content-type'); * // => "text/plain" * * req.header('Accept'); * // => undefined * * req.header('Accept', 'text/html'); * // => "text/html" * * @param {String} name * @param {String} defaultValue * @return {String} * @api public */ req.header = function(name, defaultValue){ switch (name = name.toLowerCase()) { case 'referer': case 'referrer': return this.headers.referrer || this.headers.referer || defaultValue; default: return this.headers[name] || defaultValue; } }; /** * Get `field`'s `param` value, defaulting to ''. * * Examples: * * req.get('content-disposition', 'filename'); * // => "something.png" * * @param {String} field * @param {String} param * @return {String} * @api public */ req.get = function(field, param){ var val = this.header(field); if (!val) return ''; var regexp = new RegExp(param + ' *= *(?:"([^"]+)"|([^;]+))', 'i'); if (!regexp.exec(val)) return ''; return RegExp.$1 || RegExp.$2; }; /** * Short-hand for `require('url').parse(req.url).pathname`. * * @return {String} * @api public */ req.__defineGetter__('path', function(){ return parse(this.url).pathname; }); /** * Check if the _Accept_ header is present, and includes the given `type`. * * When the _Accept_ header is not present `true` is returned. Otherwise * the given `type` is matched by an exact match, and then subtypes. You * may pass the subtype such as "html" which is then converted internally * to "text/html" using the mime lookup table. * * Examples: * * // Accept: text/html * req.accepts('html'); * // => true * * // Accept: text/*; application/json * req.accepts('html'); * req.accepts('text/html'); * req.accepts('text/plain'); * req.accepts('application/json'); * // => true * * req.accepts('image/png'); * req.accepts('png'); * // => false * * @param {String} type * @return {Boolean} * @api public */ req.accepts = function(type){ var accept = this.header('Accept'); // normalize extensions ".json" -> "json" if (type && '.' == type[0]) type = type.substr(1); // when Accept does not exist, or contains '*/*' return true if (!accept || ~accept.indexOf('*/*')) { return true; } else if (type) { // allow "html" vs "text/html" etc if (!~type.indexOf('/')) type = mime.lookup(type); // check if we have a direct match if (~accept.indexOf(type)) return true; // check if we have type/* type = type.split('/')[0] + '/*'; return !!~accept.indexOf(type); } else { return false; } }; /** * Return the value of param `name` when present or `defaultValue`. * * - Checks route placeholders, ex: _/user/:id_ * - Checks query string params, ex: ?id=12 * - Checks urlencoded body params, ex: id=12 * * To utilize urlencoded request bodies, `req.body` * should be an object. This can be done by using * the `connect.bodyParser` middleware. * * @param {String} name * @param {Mixed} defaultValue * @return {String} * @api public */ req.param = function(name, defaultValue){ // route params like /user/:id if (this.params && this.params.hasOwnProperty(name) && undefined !== this.params[name]) { return this.params[name]; } // query string params if (undefined !== this.query[name]) { return this.query[name]; } // request body params via connect.bodyParser if (this.body && undefined !== this.body[name]) { return this.body[name]; } return defaultValue; }; /** * Queue flash `msg` of the given `type`. * * Examples: * * req.flash('info', 'email sent'); * req.flash('error', 'email delivery failed'); * req.flash('info', 'email re-sent'); * // => 2 * * req.flash('info'); * // => ['email sent', 'email re-sent'] * * req.flash('info'); * // => [] * * req.flash(); * // => { error: ['email delivery failed'], info: [] } * * Formatting: * * Flash notifications also support arbitrary formatting support. * For example you may pass variable arguments to `req.flash()` * and use the %s specifier to be replaced by the associated argument: * * req.flash('info', 'email has been sent to %s.', userName); * * To add custom formatters use the `exports.flashFormatters` object. * * @param {String} type * @param {String} msg * @return {Array|Object|Number} * @api public */ req.flash = function(type, msg){ if (this.session === undefined) throw Error('req.flash() requires sessions'); var msgs = this.session.flash = this.session.flash || {}; if (type && msg) { var i = 2 , args = arguments , formatters = this.app.flashFormatters || {}; formatters.__proto__ = flashFormatters; msg = utils.miniMarkdown(msg); msg = msg.replace(/%([a-zA-Z])/g, function(_, format){ var formatter = formatters[format]; if (formatter) return formatter(utils.escape(args[i++])); }); return (msgs[type] = msgs[type] || []).push(msg); } else if (type) { var arr = msgs[type]; delete msgs[type]; return arr || []; } else { this.session.flash = {}; return msgs; } }; /** * Check if the incoming request contains the "Content-Type" * header field, and it contains the give mime `type`. * * Examples: * * // With Content-Type: text/html; charset=utf-8 * req.is('html'); * req.is('text/html'); * // => true * * // When Content-Type is application/json * req.is('json'); * req.is('application/json'); * // => true * * req.is('html'); * // => false * * Ad-hoc callbacks can also be registered with Express, to perform * assertions again the request, for example if we need an expressive * way to check if our incoming request is an image, we can register "an image" * callback: * * app.is('an image', function(req){ * return 0 == req.headers['content-type'].indexOf('image'); * }); * * Now within our route callbacks, we can use to to assert content types * such as "image/jpeg", "image/png", etc. * * app.post('/image/upload', function(req, res, next){ * if (req.is('an image')) { * // do something * } else { * next(); * } * }); * * @param {String} type * @return {Boolean} * @api public */ req.is = function(type){ var fn = this.app.is(type); if (fn) return fn(this); var ct = this.headers['content-type']; if (!ct) return false; ct = ct.split(';')[0]; if (!~type.indexOf('/')) type = mime.lookup(type); if (~type.indexOf('*')) { type = type.split('/'); ct = ct.split('/'); if ('*' == type[0] && type[1] == ct[1]) return true; if ('*' == type[1] && type[0] == ct[0]) return true; return false; } return !! ~ct.indexOf(type); }; // Callback for isXMLHttpRequest / xhr function isxhr() { return this.header('X-Requested-With', '').toLowerCase() === 'xmlhttprequest'; } /** * Check if the request was an _XMLHttpRequest_. * * @return {Boolean} * @api public */ req.__defineGetter__('isXMLHttpRequest', isxhr); req.__defineGetter__('xhr', isxhr); package/lib/response.js000644 000765 000024 0000025665 11736457113013517 0ustar00000000 000000 /*! * Express - response * Copyright(c) 2010 TJ Holowaychuk * MIT Licensed */ /** * Module dependencies. */ var fs = require('fs') , http = require('http') , path = require('path') , connect = require('connect') , utils = connect.utils , parseRange = require('./utils').parseRange , res = http.ServerResponse.prototype , send = connect.static.send , mime = require('mime') , basename = path.basename , join = path.join; /** * Send a response with the given `body` and optional `headers` and `status` code. * * Examples: * * res.send(); * res.send(new Buffer('wahoo')); * res.send({ some: 'json' }); * res.send('

some html

'); * res.send('Sorry, cant find that', 404); * res.send('text', { 'Content-Type': 'text/plain' }, 201); * res.send(404); * * @param {String|Object|Number|Buffer} body or status * @param {Object|Number} headers or status * @param {Number} status * @return {ServerResponse} * @api public */ res.send = function(body, headers, status){ // allow status as second arg if ('number' == typeof headers) { status = headers, headers = null; } // default status status = status || this.statusCode; // allow 0 args as 204 if (!arguments.length || undefined === body) status = 204; // determine content type switch (typeof body) { case 'number': if (!this.header('Content-Type')) { this.contentType('.txt'); } body = http.STATUS_CODES[status = body]; break; case 'string': if (!this.header('Content-Type')) { this.charset = this.charset || 'utf-8'; this.contentType('.html'); } break; case 'boolean': case 'object': if (Buffer.isBuffer(body)) { if (!this.header('Content-Type')) { this.contentType('.bin'); } } else { return this.json(body, headers, status); } break; } // populate Content-Length if (undefined !== body && !this.header('Content-Length')) { this.header('Content-Length', Buffer.isBuffer(body) ? body.length : Buffer.byteLength(body)); } // merge headers passed if (headers) { var fields = Object.keys(headers); for (var i = 0, len = fields.length; i < len; ++i) { var field = fields[i]; this.header(field, headers[field]); } } // strip irrelevant headers if (204 == status || 304 == status) { this.removeHeader('Content-Type'); this.removeHeader('Content-Length'); body = ''; } // respond this.statusCode = status; this.end('HEAD' == this.req.method ? null : body); return this; }; /** * Send JSON response with `obj`, optional `headers`, and optional `status`. * * Examples: * * res.json(null); * res.json({ user: 'tj' }); * res.json('oh noes!', 500); * res.json('I dont have that', 404); * * @param {Mixed} obj * @param {Object|Number} headers or status * @param {Number} status * @return {ServerResponse} * @api public */ res.json = function(obj, headers, status){ var body = JSON.stringify(obj) , callback = this.req.query.callback , jsonp = this.app.enabled('jsonp callback'); this.charset = this.charset || 'utf-8'; this.header('Content-Type', 'application/json'); if (callback && jsonp) { this.header('Content-Type', 'text/javascript'); body = callback.replace(/[^\w$.]/g, '') + '(' + body + ');'; } return this.send(body, headers, status); }; /** * Set status `code`. * * @param {Number} code * @return {ServerResponse} * @api public */ res.status = function(code){ this.statusCode = code; return this; }; /** * Transfer the file at the given `path`. Automatically sets * the _Content-Type_ response header field. `next()` is called * when `path` is a directory, or when an error occurs. * * Options: * * - `maxAge` defaulting to 0 * - `root` root directory for relative filenames * * @param {String} path * @param {Object|Function} options or fn * @param {Function} fn * @api public */ res.sendfile = function(path, options, fn){ var next = this.req.next; options = options || {}; // support function as second arg if ('function' == typeof options) { fn = options; options = {}; } options.path = encodeURIComponent(path); options.callback = fn; send(this.req, this, next, options); }; /** * Set _Content-Type_ response header passed through `mime.lookup()`. * * Examples: * * var filename = 'path/to/image.png'; * res.contentType(filename); * // res.headers['Content-Type'] is now "image/png" * * res.contentType('.html'); * res.contentType('html'); * res.contentType('json'); * res.contentType('png'); * * @param {String} type * @return {String} the resolved mime type * @api public */ res.contentType = function(type){ return this.header('Content-Type', mime.lookup(type)); }; /** * Set _Content-Disposition_ header to _attachment_ with optional `filename`. * * @param {String} filename * @return {ServerResponse} * @api public */ res.attachment = function(filename){ if (filename) this.contentType(filename); this.header('Content-Disposition', filename ? 'attachment; filename="' + basename(filename) + '"' : 'attachment'); return this; }; /** * Transfer the file at the given `path`, with optional * `filename` as an attachment and optional callback `fn(err)`, * and optional `fn2(err)` which is invoked when an error has * occurred after header has been sent. * * @param {String} path * @param {String|Function} filename or fn * @param {Function} fn * @param {Function} fn2 * @api public */ res.download = function(path, filename, fn, fn2){ var self = this; // support callback as second arg if ('function' == typeof filename) { fn2 = fn; fn = filename; filename = null; } // transfer the file this.attachment(filename || path).sendfile(path, function(err){ var sentHeader = self._header; if (err) { if (!sentHeader) self.removeHeader('Content-Disposition'); if (sentHeader) { fn2 && fn2(err); } else if (fn) { fn(err); } else { self.req.next(err); } } else if (fn) { fn(); } }); }; /** * Set or get response header `name` with optional `val`. * * @param {String} name * @param {String} val * @return {ServerResponse} for chaining * @api public */ res.header = function(name, val){ if (1 == arguments.length) return this.getHeader(name); this.setHeader(name, val); return this; }; /** * Clear cookie `name`. * * @param {String} name * @param {Object} options * @api public */ res.clearCookie = function(name, options){ var opts = { expires: new Date(1) }; this.cookie(name, '', options ? utils.merge(options, opts) : opts); }; /** * Set cookie `name` to `val`, with the given `options`. * * Options: * * - `maxAge` max-age in milliseconds, converted to `expires` * - `path` defaults to the "basepath" setting which is typically "/" * * Examples: * * // "Remember Me" for 15 minutes * res.cookie('rememberme', '1', { expires: new Date(Date.now() + 900000), httpOnly: true }); * * // save as above * res.cookie('rememberme', '1', { maxAge: 900000, httpOnly: true }) * * @param {String} name * @param {String} val * @param {Options} options * @api public */ res.cookie = function(name, val, options){ options = options || {}; if ('maxAge' in options) options.expires = new Date(Date.now() + options.maxAge); if (undefined === options.path) options.path = this.app.set('basepath'); var cookie = utils.serializeCookie(name, val, options); this.header('Set-Cookie', cookie); }; /** * Redirect to the given `url` with optional response `status` * defauling to 302. * * The given `url` can also be the name of a mapped url, for * example by default express supports "back" which redirects * to the _Referrer_ or _Referer_ headers or the application's * "basepath" setting. Express also supports "basepath" out of the box, * which can be set via `app.set('basepath', '/blog');`, and defaults * to '/'. * * Redirect Mapping: * * To extend the redirect mapping capabilities that Express provides, * we may use the `app.redirect()` method: * * app.redirect('google', 'http://google.com'); * * Now in a route we may call: * * res.redirect('google'); * * We may also map dynamic redirects: * * app.redirect('comments', function(req, res){ * return '/post/' + req.params.id + '/comments'; * }); * * So now we may do the following, and the redirect will dynamically adjust to * the context of the request. If we called this route with _GET /post/12_ our * redirect _Location_ would be _/post/12/comments_. * * app.get('/post/:id', function(req, res){ * res.redirect('comments'); * }); * * Unless an absolute `url` is given, the app's mount-point * will be respected. For example if we redirect to `/posts`, * and our app is mounted at `/blog` we will redirect to `/blog/posts`. * * @param {String} url * @param {Number} code * @api public */ res.redirect = function(url, status){ var app = this.app , req = this.req , base = app.set('basepath') || app.route , status = status || 302 , head = 'HEAD' == req.method , body; // Setup redirect map var map = { back: req.header('Referrer', base) , home: base }; // Support custom redirect map map.__proto__ = app.redirects; // Attempt mapped redirect var mapped = 'function' == typeof map[url] ? map[url](req, this) : map[url]; // Perform redirect url = mapped || url; // Relative if (!~url.indexOf('://')) { // Respect mount-point if ('/' != base && 0 != url.indexOf(base)) url = base + url; // Absolute var host = req.headers.host , tls = req.connection.encrypted; url = 'http' + (tls ? 's' : '') + '://' + host + url; } // Support text/{plain,html} by default if (req.accepts('html')) { body = '

' + http.STATUS_CODES[status] + '. Redirecting to ' + url + '

'; this.header('Content-Type', 'text/html'); } else { body = http.STATUS_CODES[status] + '. Redirecting to ' + url; this.header('Content-Type', 'text/plain'); } // Respond this.statusCode = status; this.header('Location', url); this.end(head ? null : body); }; /** * Assign the view local variable `name` to `val` or return the * local previously assigned to `name`. * * @param {String} name * @param {Mixed} val * @return {Mixed} val * @api public */ res.local = function(name, val){ this._locals = this._locals || {}; return undefined === val ? this._locals[name] : this._locals[name] = val; }; /** * Assign several locals with the given `obj`, * or return the locals. * * @param {Object} obj * @return {Object|Undefined} * @api public */ res.locals = res.helpers = function(obj){ if (obj) { for (var key in obj) { this.local(key, obj[key]); } } else { return this._locals; } }; package/lib/router/000755 000765 000024 0000000000 11736457244012632 5ustar00000000 000000 package/lib/router/collection.js000644 000765 000024 0000001524 11736457113015320 0ustar00000000 000000 /*! * Express - router - Collection * Copyright(c) 2010 TJ Holowaychuk * MIT Licensed */ /** * Expose `Collection`. */ module.exports = Collection; /** * Initialize a new route `Collection` * with the given `router`. * * @param {Router} router * @api private */ function Collection(router) { Array.apply(this, arguments); this.router = router; } /** * Inherit from `Array.prototype`. */ Collection.prototype.__proto__ = Array.prototype; /** * Remove the routes in this collection. * * @return {Collection} of routes removed * @api public */ Collection.prototype.remove = function(){ var router = this.router , len = this.length , ret = new Collection(this.router); for (var i = 0; i < len; ++i) { if (router.remove(this[i])) { ret.push(this[i]); } } return ret; }; package/lib/router/index.js000644 000765 000024 0000020053 11736457113014272 0ustar00000000 000000 /*! * Express - Router * Copyright(c) 2010 TJ Holowaychuk * MIT Licensed */ /** * Module dependencies. */ var Route = require('./route') , Collection = require('./collection') , utils = require('../utils') , parse = require('url').parse , toArray = utils.toArray; /** * Expose `Router` constructor. */ exports = module.exports = Router; /** * Expose HTTP methods. */ var methods = exports.methods = require('./methods'); /** * Initialize a new `Router` with the given `app`. * * @param {express.HTTPServer} app * @api private */ function Router(app) { var self = this; this.app = app; this.routes = {}; this.params = {}; this._params = []; this.middleware = function(req, res, next){ self._dispatch(req, res, next); }; } /** * Register a param callback `fn` for the given `name`. * * @param {String|Function} name * @param {Function} fn * @return {Router} for chaining * @api public */ Router.prototype.param = function(name, fn){ // param logic if ('function' == typeof name) { this._params.push(name); return; } // apply param functions var params = this._params , len = params.length , ret; for (var i = 0; i < len; ++i) { if (ret = params[i](name, fn)) { fn = ret; } } // ensure we end up with a // middleware function if ('function' != typeof fn) { throw new Error('invalid param() call for ' + name + ', got ' + fn); } (this.params[name] = this.params[name] || []).push(fn); return this; }; /** * Return a `Collection` of all routes defined. * * @return {Collection} * @api public */ Router.prototype.all = function(){ return this.find(function(){ return true; }); }; /** * Remove the given `route`, returns * a bool indicating if the route was present * or not. * * @param {Route} route * @return {Boolean} * @api public */ Router.prototype.remove = function(route){ var routes = this.routes[route.method] , len = routes.length; for (var i = 0; i < len; ++i) { if (route == routes[i]) { routes.splice(i, 1); return true; } } }; /** * Return routes with route paths matching `path`. * * @param {String} method * @param {String} path * @return {Collection} * @api public */ Router.prototype.lookup = function(method, path){ return this.find(function(route){ return path == route.path && (route.method == method || method == 'all'); }); }; /** * Return routes with regexps that match the given `url`. * * @param {String} method * @param {String} url * @return {Collection} * @api public */ Router.prototype.match = function(method, url){ return this.find(function(route){ return route.match(url) && (route.method == method || method == 'all'); }); }; /** * Find routes based on the return value of `fn` * which is invoked once per route. * * @param {Function} fn * @return {Collection} * @api public */ Router.prototype.find = function(fn){ var len = methods.length , ret = new Collection(this) , method , routes , route; for (var i = 0; i < len; ++i) { method = methods[i]; routes = this.routes[method]; if (!routes) continue; for (var j = 0, jlen = routes.length; j < jlen; ++j) { route = routes[j]; if (fn(route)) ret.push(route); } } return ret; }; /** * Route dispatcher aka the route "middleware". * * @param {IncomingMessage} req * @param {ServerResponse} res * @param {Function} next * @api private */ Router.prototype._dispatch = function(req, res, next){ var params = this.params , self = this; // route dispatch (function pass(i, err){ var paramCallbacks , paramIndex = 0 , paramVal , route , keys , key , ret; // match next route function nextRoute(err) { pass(req._route_index + 1, err); } // match route req.route = route = self._match(req, i); // implied OPTIONS if (!route && 'OPTIONS' == req.method) return self._options(req, res); // no route if (!route) return next(err); // we have a route // start at param 0 req.params = route.params; keys = route.keys; i = 0; // param callbacks function param(err) { paramIndex = 0; key = keys[i++]; paramVal = key && req.params[key.name]; paramCallbacks = key && params[key.name]; try { if ('route' == err) { nextRoute(); } else if (err) { i = 0; callbacks(err); } else if (paramCallbacks && undefined !== paramVal) { paramCallback(); } else if (key) { param(); } else { i = 0; callbacks(); } } catch (err) { param(err); } }; param(err); // single param callbacks function paramCallback(err) { var fn = paramCallbacks[paramIndex++]; if (err || !fn) return param(err); fn(req, res, paramCallback, paramVal, key.name); } // invoke route callbacks function callbacks(err) { var fn = route.callbacks[i++]; try { if ('route' == err) { nextRoute(); } else if (err && fn) { if (fn.length < 4) return callbacks(err); fn(err, req, res, callbacks); } else if (fn) { fn(req, res, callbacks); } else { nextRoute(err); } } catch (err) { callbacks(err); } } })(0); }; /** * Respond to __OPTIONS__ method. * * @param {IncomingMessage} req * @param {ServerResponse} res * @api private */ Router.prototype._options = function(req, res){ var path = parse(req.url).pathname , body = this._optionsFor(path).join(','); res.send(body, { Allow: body }); }; /** * Return an array of HTTP verbs or "options" for `path`. * * @param {String} path * @return {Array} * @api private */ Router.prototype._optionsFor = function(path){ var self = this; return methods.filter(function(method){ var routes = self.routes[method]; if (!routes || 'options' == method) return; for (var i = 0, len = routes.length; i < len; ++i) { if (routes[i].match(path)) return true; } }).map(function(method){ return method.toUpperCase(); }); }; /** * Attempt to match a route for `req` * starting from offset `i`. * * @param {IncomingMessage} req * @param {Number} i * @return {Route} * @api private */ Router.prototype._match = function(req, i){ var method = req.method.toLowerCase() , url = parse(req.url) , path = url.pathname , routes = this.routes , captures , route , keys; // pass HEAD to GET routes if ('head' == method) method = 'get'; // routes for this method if (routes = routes[method]) { // matching routes for (var len = routes.length; i < len; ++i) { route = routes[i]; if (captures = route.match(path)) { keys = route.keys; route.params = []; // params from capture groups for (var j = 1, jlen = captures.length; j < jlen; ++j) { var key = keys[j-1] , val = 'string' == typeof captures[j] ? decodeURIComponent(captures[j]) : captures[j]; if (key) { route.params[key.name] = val; } else { route.params.push(val); } } // all done req._route_index = i; return route; } } } }; /** * Route `method`, `path`, and one or more callbacks. * * @param {String} method * @param {String} path * @param {Function} callback... * @return {Router} for chaining * @api private */ Router.prototype._route = function(method, path, callbacks){ var app = this.app , callbacks = utils.flatten(toArray(arguments, 2)); // ensure path was given if (!path) throw new Error('app.' + method + '() requires a path'); // create the route var route = new Route(method, path, callbacks, { sensitive: app.enabled('case sensitive routes') , strict: app.enabled('strict routing') }); // add it (this.routes[method] = this.routes[method] || []) .push(route); return this; }; package/lib/router/methods.js000644 000765 000024 0000003232 11736457122014626 0ustar00000000 000000 /*! * Express - router - methods * Copyright(c) 2010 TJ Holowaychuk * MIT Licensed */ /** * Hypertext Transfer Protocol -- HTTP/1.1 * http://www.ietf.org/rfc/rfc2616.txt */ var RFC2616 = ['OPTIONS', 'GET', 'POST', 'PUT', 'DELETE', 'TRACE', 'CONNECT']; /** * HTTP Extensions for Distributed Authoring -- WEBDAV * http://www.ietf.org/rfc/rfc2518.txt */ var RFC2518 = ['PROPFIND', 'PROPPATCH', 'MKCOL', 'COPY', 'MOVE', 'LOCK', 'UNLOCK']; /** * Versioning Extensions to WebDAV * http://www.ietf.org/rfc/rfc3253.txt */ var RFC3253 = ['VERSION-CONTROL', 'REPORT', 'CHECKOUT', 'CHECKIN', 'UNCHECKOUT', 'MKWORKSPACE', 'UPDATE', 'LABEL', 'MERGE', 'BASELINE-CONTROL', 'MKACTIVITY']; /** * Ordered Collections Protocol (WebDAV) * http://www.ietf.org/rfc/rfc3648.txt */ var RFC3648 = ['ORDERPATCH']; /** * Web Distributed Authoring and Versioning (WebDAV) Access Control Protocol * http://www.ietf.org/rfc/rfc3744.txt */ var RFC3744 = ['ACL']; /** * Web Distributed Authoring and Versioning (WebDAV) SEARCH * http://www.ietf.org/rfc/rfc5323.txt */ var RFC5323 = ['SEARCH']; /** * PATCH Method for HTTP * http://www.ietf.org/rfc/rfc5789.txt */ var RFC5789 = ['PATCH']; /** * PURGE Method for caching reverse-proxy * http://wiki.squid-cache.org/SquidFaq/OperatingSquid#How_can_I_purge_an_object_from_my_cache.3F * https://www.varnish-cache.org/docs/trunk/tutorial/purging.html */ var CACHE_PURGE = ['PURGE']; /** * Expose the methods. */ module.exports = [].concat( RFC2616 , RFC2518 , RFC3253 , RFC3648 , RFC3744 , RFC5323 , RFC5789 , CACHE_PURGE).map(function(method){ return method.toLowerCase(); }); package/lib/router/route.js000644 000765 000024 0000004045 11736457113014324 0ustar00000000 000000 /*! * Express - router - Route * Copyright(c) 2010 TJ Holowaychuk * MIT Licensed */ /** * Expose `Route`. */ module.exports = Route; /** * Initialize `Route` with the given HTTP `method`, `path`, * and an array of `callbacks` and `options`. * * Options: * * - `sensitive` enable case-sensitive routes * - `strict` enable strict matching for trailing slashes * * @param {String} method * @param {String} path * @param {Array} callbacks * @param {Object} options. * @api private */ function Route(method, path, callbacks, options) { options = options || {}; this.path = path; this.method = method; this.callbacks = callbacks; this.regexp = normalize(path , this.keys = [] , options.sensitive , options.strict); } /** * Check if this route matches `path` and return captures made. * * @param {String} path * @return {Array} * @api private */ Route.prototype.match = function(path){ return this.regexp.exec(path); }; /** * Normalize the given path string, * returning a regular expression. * * An empty array should be passed, * which will contain the placeholder * key names. For example "/user/:id" will * then contain ["id"]. * * @param {String|RegExp} path * @param {Array} keys * @param {Boolean} sensitive * @param {Boolean} strict * @return {RegExp} * @api private */ function normalize(path, keys, sensitive, strict) { if (path instanceof RegExp) return path; path = path .concat(strict ? '' : '/?') .replace(/\/\(/g, '(?:/') .replace(/(\/)?(\.)?:(\w+)(?:(\(.*?\)))?(\?)?/g, function(_, slash, format, key, capture, optional){ keys.push({ name: key, optional: !! optional }); slash = slash || ''; return '' + (optional ? '' : slash) + '(?:' + (optional ? slash : '') + (format || '') + (capture || (format && '([^/.]+?)' || '([^/]+?)')) + ')' + (optional || ''); }) .replace(/([\/.])/g, '\\$1') .replace(/\*/g, '(.*)'); return new RegExp('^' + path + '$', sensitive ? '' : 'i'); } package/lib/utils.js000644 000765 000024 0000005671 11736457113013014 0ustar00000000 000000 /*! * Express - Utils * Copyright(c) 2010 TJ Holowaychuk * MIT Licensed */ /** * Check if `path` looks absolute. * * @param {String} path * @return {Boolean} * @api private */ exports.isAbsolute = function(path){ if ('/' == path[0]) return true; if (':' == path[1] && '\\' == path[2]) return true; }; /** * Merge object `b` with `a` giving precedence to * values in object `a`. * * @param {Object} a * @param {Object} b * @return {Object} a * @api private */ exports.union = function(a, b){ if (a && b) { var keys = Object.keys(b) , len = keys.length , key; for (var i = 0; i < len; ++i) { key = keys[i]; if (!a.hasOwnProperty(key)) { a[key] = b[key]; } } } return a; }; /** * Flatten the given `arr`. * * @param {Array} arr * @return {Array} * @api private */ exports.flatten = function(arr, ret){ var ret = ret || [] , len = arr.length; for (var i = 0; i < len; ++i) { if (Array.isArray(arr[i])) { exports.flatten(arr[i], ret); } else { ret.push(arr[i]); } } return ret; }; /** * Parse mini markdown implementation. * The following conversions are supported, * primarily for the "flash" middleware: * * _foo_ or *foo* become foo * __foo__ or **foo** become foo * [A](B) becomes A * * @param {String} str * @return {String} * @api private */ exports.miniMarkdown = function(str){ return String(str) .replace(/(__|\*\*)(.*?)\1/g, '$2') .replace(/(_|\*)(.*?)\1/g, '$2') .replace(/\[([^\]]+)\]\(([^)]+)\)/g, '$1'); }; /** * Escape special characters in the given string of html. * * @param {String} html * @return {String} * @api private */ exports.escape = function(html) { return String(html) .replace(/&/g, '&') .replace(/"/g, '"') .replace(//g, '>'); }; /** * Parse "Range" header `str` relative to the given file `size`. * * @param {Number} size * @param {String} str * @return {Array} * @api private */ exports.parseRange = function(size, str){ var valid = true; var arr = str.substr(6).split(',').map(function(range){ var range = range.split('-') , start = parseInt(range[0], 10) , end = parseInt(range[1], 10); // -500 if (isNaN(start)) { start = size - end; end = size - 1; // 500- } else if (isNaN(end)) { end = size - 1; } // Invalid if (isNaN(start) || isNaN(end) || start > end) valid = false; return { start: start, end: end }; }); return valid ? arr : undefined; }; /** * Fast alternative to `Array.prototype.slice.call()`. * * @param {Arguments} args * @param {Number} n * @return {Array} * @api public */ exports.toArray = function(args, i){ var arr = [] , len = args.length , i = i || 0; for (; i < len; ++i) arr.push(args[i]); return arr; }; package/lib/view/000755 000765 000024 0000000000 11736457244012264 5ustar00000000 000000 package/lib/view/partial.js000644 000765 000024 0000001406 11736457113014252 0ustar00000000 000000 /*! * Express - view - Partial * Copyright(c) 2010 TJ Holowaychuk * MIT Licensed */ /** * Memory cache. */ var cache = {}; /** * Resolve partial object name from the view path. * * Examples: * * "user.ejs" becomes "user" * "forum thread.ejs" becomes "forumThread" * "forum/thread/post.ejs" becomes "post" * "blog-post.ejs" becomes "blogPost" * * @return {String} * @api private */ exports.resolveObjectName = function(view){ return cache[view] || (cache[view] = view .split('/') .slice(-1)[0] .split('.')[0] .replace(/^_/, '') .replace(/[^a-zA-Z0-9 ]+/g, ' ') .split(/ +/).map(function(word, i){ return i ? word[0].toUpperCase() + word.substr(1) : word; }).join('')); };package/lib/view/view.js000644 000765 000024 0000010207 11736457113013567 0ustar00000000 000000 /*! * Express - View * Copyright(c) 2010 TJ Holowaychuk * MIT Licensed */ /** * Module dependencies. */ var path = require('path') , utils = require('../utils') , extname = path.extname , dirname = path.dirname , basename = path.basename , fs = require('fs') , stat = fs.statSync; /** * Expose `View`. */ exports = module.exports = View; /** * Require cache. */ var cache = {}; /** * Initialize a new `View` with the given `view` path and `options`. * * @param {String} view * @param {Object} options * @api private */ function View(view, options) { options = options || {}; this.view = view; this.root = options.root; this.relative = false !== options.relative; this.defaultEngine = options.defaultEngine; this.parent = options.parentView; this.basename = basename(view); this.engine = this.resolveEngine(); this.extension = '.' + this.engine; this.name = this.basename.replace(this.extension, ''); this.path = this.resolvePath(); this.dirname = dirname(this.path); if (options.attempts) { if (!~options.attempts.indexOf(this.path)) options.attempts.push(this.path); } }; /** * Check if the view path exists. * * @return {Boolean} * @api public */ View.prototype.__defineGetter__('exists', function(){ try { stat(this.path); return true; } catch (err) { return false; } }); /** * Resolve view engine. * * @return {String} * @api private */ View.prototype.resolveEngine = function(){ // Explicit if (~this.basename.indexOf('.')) return extname(this.basename).substr(1); // Inherit from parent if (this.parent) return this.parent.engine; // Default return this.defaultEngine; }; /** * Resolve view path. * * @return {String} * @api private */ View.prototype.resolvePath = function(){ var path = this.view; // Implicit engine if (!~this.basename.indexOf('.')) path += this.extension; // Absolute if (utils.isAbsolute(path)) return path; // Relative to parent if (this.relative && this.parent) return this.parent.dirname + '/' + path; // Relative to root return this.root ? this.root + '/' + path : path; }; /** * Get view contents. This is a one-time hit, so we * can afford to be sync. * * @return {String} * @api public */ View.prototype.__defineGetter__('contents', function(){ return fs.readFileSync(this.path, 'utf8'); }); /** * Get template engine api, cache exports to reduce * require() calls. * * @return {Object} * @api public */ View.prototype.__defineGetter__('templateEngine', function(){ var ext = this.extension; return cache[ext] || (cache[ext] = require(this.engine)); }); /** * Return root path alternative. * * @return {String} * @api public */ View.prototype.__defineGetter__('rootPath', function(){ this.relative = false; return this.resolvePath(); }); /** * Return index path alternative. * * @return {String} * @api public */ View.prototype.__defineGetter__('indexPath', function(){ return this.dirname + '/' + this.basename.replace(this.extension, '') + '/index' + this.extension; }); /** * Return ..//index path alternative. * * @return {String} * @api public */ View.prototype.__defineGetter__('upIndexPath', function(){ return this.dirname + '/../' + this.name + '/index' + this.extension; }); /** * Return _ prefix path alternative * * @return {String} * @api public */ View.prototype.__defineGetter__('prefixPath', function(){ return this.dirname + '/_' + this.basename; }); /** * Register the given template engine `exports` * as `ext`. For example we may wish to map ".html" * files to jade: * * app.register('.html', require('jade')); * * or * * app.register('html', require('jade')); * * This is also useful for libraries that may not * match extensions correctly. For example my haml.js * library is installed from npm as "hamljs" so instead * of layout.hamljs, we can register the engine as ".haml": * * app.register('.haml', require('haml-js')); * * @param {String} ext * @param {Object} obj * @api public */ exports.register = function(ext, exports) { if ('.' != ext[0]) ext = '.' + ext; cache[ext] = exports; }; package/lib/view.js000644 000765 000024 0000025073 11736457113012624 0ustar00000000 000000 /*! * Express - view * Copyright(c) 2010 TJ Holowaychuk * MIT Licensed */ /** * Module dependencies. */ var path = require('path') , extname = path.extname , dirname = path.dirname , basename = path.basename , utils = require('connect').utils , View = require('./view/view') , partial = require('./view/partial') , union = require('./utils').union , merge = utils.merge , http = require('http') , res = http.ServerResponse.prototype; /** * Expose constructors. */ exports = module.exports = View; /** * Export template engine registrar. */ exports.register = View.register; /** * Lookup and compile `view` with cache support by supplying * both the `cache` object and `cid` string, * followed by `options` passed to `exports.lookup()`. * * @param {String} view * @param {Object} cache * @param {Object} cid * @param {Object} options * @return {View} * @api private */ exports.compile = function(view, cache, cid, options){ if (cache && cid && cache[cid]){ options.filename = cache[cid].path; return cache[cid]; } // lookup view = exports.lookup(view, options); // hints if (!view.exists) { if (options.hint) hintAtViewPaths(view.original, options); var err = new Error('failed to locate view "' + view.original.view + '"'); err.view = view.original; throw err; } // compile options.filename = view.path; view.fn = view.templateEngine.compile(view.contents, options); cache[cid] = view; return view; }; /** * Lookup `view`, returning an instanceof `View`. * * Options: * * - `root` root directory path * - `defaultEngine` default template engine * - `parentView` parent `View` object * - `cache` cache object * - `cacheid` optional cache id * * Lookup: * * - partial `_` * - any `/index` * - non-layout `..//index` * - any `/` * - partial `/_` * * @param {String} view * @param {Object} options * @return {View} * @api private */ exports.lookup = function(view, options){ var orig = view = new View(view, options) , partial = options.isPartial , layout = options.isLayout; // Try _ prefix ex: ./views/_.jade // taking precedence over the direct path if (partial) { view = new View(orig.prefixPath, options); if (!view.exists) view = orig; } // Try index ex: ./views/user/index.jade if (!layout && !view.exists) view = new View(orig.indexPath, options); // Try ..//index ex: ../user/index.jade // when calling partial('user') within the same dir if (!layout && !view.exists) view = new View(orig.upIndexPath, options); // Try root ex: /user.jade if (!view.exists) view = new View(orig.rootPath, options); // Try root _ prefix ex: /_user.jade if (!view.exists && partial) view = new View(view.prefixPath, options); view.original = orig; return view; }; /** * Partial render helper. * * @api private */ function renderPartial(res, view, options, parentLocals, parent){ var collection, object, locals; if (options) { // collection if (options.collection) { collection = options.collection; delete options.collection; } else if ('length' in options) { collection = options; options = {}; } // locals if (options.locals) { locals = options.locals; delete options.locals; } // object if ('Object' != options.constructor.name) { object = options; options = {}; } else if (undefined != options.object) { object = options.object; delete options.object; } } else { options = {}; } // Inherit locals from parent union(options, parentLocals); // Merge locals if (locals) merge(options, locals); // Partials dont need layouts options.isPartial = true; options.layout = false; // Deduce name from view path var name = options.as || partial.resolveObjectName(view); // Render partial function render(){ if (object) { if ('string' == typeof name) { options[name] = object; } else if (name === global) { merge(options, object); } } return res.render(view, options, null, parent, true); } // Collection support if (collection) { var len = collection.length , buf = '' , keys , key , val; options.collectionLength = len; if ('number' == typeof len || Array.isArray(collection)) { for (var i = 0; i < len; ++i) { val = collection[i]; options.firstInCollection = i == 0; options.indexInCollection = i; options.lastInCollection = i == len - 1; object = val; buf += render(); } } else { keys = Object.keys(collection); len = keys.length; options.collectionLength = len; options.collectionKeys = keys; for (var i = 0; i < len; ++i) { key = keys[i]; val = collection[key]; options.keyInCollection = key; options.firstInCollection = i == 0; options.indexInCollection = i; options.lastInCollection = i == len - 1; object = val; buf += render(); } } return buf; } else { return render(); } }; /** * Render `view` partial with the given `options`. Optionally a * callback `fn(err, str)` may be passed instead of writing to * the socket. * * Options: * * - `object` Single object with name derived from the view (unless `as` is present) * * - `as` Variable name for each `collection` value, defaults to the view name. * * as: 'something' will add the `something` local variable * * as: this will use the collection value as the template context * * as: global will merge the collection value's properties with `locals` * * - `collection` Array of objects, the name is derived from the view name itself. * For example _video.html_ will have a object _video_ available to it. * * @param {String} view * @param {Object|Array|Function} options, collection, callback, or object * @param {Function} fn * @return {String} * @api public */ res.partial = function(view, options, fn){ var app = this.app , options = options || {} , viewEngine = app.set('view engine') , parent = {}; // accept callback as second argument if ('function' == typeof options) { fn = options; options = {}; } // root "views" option parent.dirname = app.set('views') || process.cwd() + '/views'; // utilize "view engine" option if (viewEngine) parent.engine = viewEngine; // render the partial try { var str = renderPartial(this, view, options, null, parent); } catch (err) { if (fn) { fn(err); } else { this.req.next(err); } return; } // callback or transfer if (fn) { fn(null, str); } else { this.send(str); } }; /** * Render `view` with the given `options` and optional callback `fn`. * When a callback function is given a response will _not_ be made * automatically, however otherwise a response of _200_ and _text/html_ is given. * * Options: * * - `scope` Template evaluation context (the value of `this`) * - `debug` Output debugging information * - `status` Response status code * * @param {String} view * @param {Object|Function} options or callback function * @param {Function} fn * @api public */ res.render = function(view, opts, fn, parent, sub){ // support callback function as second arg if ('function' == typeof opts) { fn = opts, opts = null; } try { return this._render(view, opts, fn, parent, sub); } catch (err) { // callback given if (fn) { fn(err); // unwind to root call to prevent multiple callbacks } else if (sub) { throw err; // root template, next(err) } else { this.req.next(err); } } }; // private render() res._render = function(view, opts, fn, parent, sub){ var options = {} , self = this , app = this.app , helpers = app._locals , dynamicHelpers = app.dynamicViewHelpers , viewOptions = app.set('view options') , root = app.set('views') || process.cwd() + '/views'; // cache id var cid = app.enabled('view cache') ? view + (parent ? ':' + parent.path : '') : false; // merge "view options" if (viewOptions) merge(options, viewOptions); // merge res._locals if (this._locals) merge(options, this._locals); // merge render() options if (opts) merge(options, opts); // merge render() .locals if (opts && opts.locals) merge(options, opts.locals); // status support if (options.status) this.statusCode = options.status; // capture attempts options.attempts = []; var partial = options.isPartial , layout = options.layout; // Layout support if (true === layout || undefined === layout) { layout = 'layout'; } // Default execution scope to a plain object options.scope = options.scope || {}; // Populate view options.parentView = parent; // "views" setting options.root = root; // "view engine" setting options.defaultEngine = app.set('view engine'); // charset option if (options.charset) this.charset = options.charset; // Dynamic helper support if (false !== options.dynamicHelpers) { // cache if (!this.__dynamicHelpers) { this.__dynamicHelpers = {}; for (var key in dynamicHelpers) { this.__dynamicHelpers[key] = dynamicHelpers[key].call( this.app , this.req , this); } } // apply merge(options, this.__dynamicHelpers); } // Merge view helpers union(options, helpers); // Always expose partial() as a local options.partial = function(path, opts){ return renderPartial(self, path, opts, options, view); }; // View lookup options.hint = app.enabled('hints'); view = exports.compile(view, app.cache, cid, options); // layout helper options.layout = function(path){ layout = path; }; // render var str = view.fn.call(options.scope, options); // layout expected if (layout) { options.isLayout = true; options.layout = false; options.body = str; this.render(layout, options, fn, view, true); // partial return } else if (partial) { return str; // render complete, and // callback given } else if (fn) { fn(null, str); // respond } else { this.send(str); } } /** * Hint at view path resolution, outputting the * paths that Express has tried. * * @api private */ function hintAtViewPaths(view, options) { console.error(); console.error('failed to locate view "' + view.view + '", tried:'); options.attempts.forEach(function(path){ console.error(' - %s', path); }); console.error(); } package/lib-cov/000755 000765 000024 0000000000 11736457244012077 5ustar00000000 000000 package/lib-cov/application.js000644 000765 000024 0000073413 11722507472014742 0ustar00000000 000000 /* automatically generated by JSCoverage - do not edit */ if (typeof _$jscoverage === 'undefined') _$jscoverage = {}; if (! _$jscoverage['application.js']) { _$jscoverage['application.js'] = []; _$jscoverage['application.js'][12] = 0; _$jscoverage['application.js'][29] = 0; _$jscoverage['application.js'][41] = 0; _$jscoverage['application.js'][42] = 0; _$jscoverage['application.js'][43] = 0; _$jscoverage['application.js'][44] = 0; _$jscoverage['application.js'][45] = 0; _$jscoverage['application.js'][46] = 0; _$jscoverage['application.js'][47] = 0; _$jscoverage['application.js'][50] = 0; _$jscoverage['application.js'][51] = 0; _$jscoverage['application.js'][52] = 0; _$jscoverage['application.js'][55] = 0; _$jscoverage['application.js'][56] = 0; _$jscoverage['application.js'][61] = 0; _$jscoverage['application.js'][62] = 0; _$jscoverage['application.js'][71] = 0; _$jscoverage['application.js'][72] = 0; _$jscoverage['application.js'][75] = 0; _$jscoverage['application.js'][76] = 0; _$jscoverage['application.js'][79] = 0; _$jscoverage['application.js'][80] = 0; _$jscoverage['application.js'][83] = 0; _$jscoverage['application.js'][84] = 0; _$jscoverage['application.js'][85] = 0; _$jscoverage['application.js'][89] = 0; _$jscoverage['application.js'][90] = 0; _$jscoverage['application.js'][91] = 0; _$jscoverage['application.js'][93] = 0; _$jscoverage['application.js'][94] = 0; _$jscoverage['application.js'][95] = 0; _$jscoverage['application.js'][98] = 0; _$jscoverage['application.js'][102] = 0; _$jscoverage['application.js'][103] = 0; _$jscoverage['application.js'][104] = 0; _$jscoverage['application.js'][105] = 0; _$jscoverage['application.js'][106] = 0; _$jscoverage['application.js'][107] = 0; _$jscoverage['application.js'][108] = 0; _$jscoverage['application.js'][112] = 0; _$jscoverage['application.js'][115] = 0; _$jscoverage['application.js'][116] = 0; _$jscoverage['application.js'][119] = 0; _$jscoverage['application.js'][120] = 0; _$jscoverage['application.js'][132] = 0; _$jscoverage['application.js'][133] = 0; _$jscoverage['application.js'][145] = 0; _$jscoverage['application.js'][146] = 0; _$jscoverage['application.js'][159] = 0; _$jscoverage['application.js'][160] = 0; _$jscoverage['application.js'][163] = 0; _$jscoverage['application.js'][166] = 0; _$jscoverage['application.js'][169] = 0; _$jscoverage['application.js'][170] = 0; _$jscoverage['application.js'][171] = 0; _$jscoverage['application.js'][172] = 0; _$jscoverage['application.js'][173] = 0; _$jscoverage['application.js'][174] = 0; _$jscoverage['application.js'][175] = 0; _$jscoverage['application.js'][180] = 0; _$jscoverage['application.js'][181] = 0; _$jscoverage['application.js'][184] = 0; _$jscoverage['application.js'][185] = 0; _$jscoverage['application.js'][186] = 0; _$jscoverage['application.js'][189] = 0; _$jscoverage['application.js'][209] = 0; _$jscoverage['application.js'][210] = 0; _$jscoverage['application.js'][211] = 0; _$jscoverage['application.js'][212] = 0; _$jscoverage['application.js'][274] = 0; _$jscoverage['application.js'][275] = 0; _$jscoverage['application.js'][279] = 0; _$jscoverage['application.js'][280] = 0; _$jscoverage['application.js'][281] = 0; _$jscoverage['application.js'][282] = 0; _$jscoverage['application.js'][286] = 0; _$jscoverage['application.js'][287] = 0; _$jscoverage['application.js'][290] = 0; _$jscoverage['application.js'][291] = 0; _$jscoverage['application.js'][292] = 0; _$jscoverage['application.js'][296] = 0; _$jscoverage['application.js'][309] = 0; _$jscoverage['application.js'][310] = 0; _$jscoverage['application.js'][311] = 0; _$jscoverage['application.js'][312] = 0; _$jscoverage['application.js'][313] = 0; _$jscoverage['application.js'][314] = 0; _$jscoverage['application.js'][317] = 0; _$jscoverage['application.js'][318] = 0; _$jscoverage['application.js'][331] = 0; _$jscoverage['application.js'][332] = 0; _$jscoverage['application.js'][345] = 0; _$jscoverage['application.js'][346] = 0; _$jscoverage['application.js'][357] = 0; _$jscoverage['application.js'][358] = 0; _$jscoverage['application.js'][369] = 0; _$jscoverage['application.js'][370] = 0; _$jscoverage['application.js'][381] = 0; _$jscoverage['application.js'][382] = 0; _$jscoverage['application.js'][411] = 0; _$jscoverage['application.js'][412] = 0; _$jscoverage['application.js'][414] = 0; _$jscoverage['application.js'][415] = 0; _$jscoverage['application.js'][416] = 0; _$jscoverage['application.js'][417] = 0; _$jscoverage['application.js'][430] = 0; _$jscoverage['application.js'][431] = 0; _$jscoverage['application.js'][432] = 0; _$jscoverage['application.js'][439] = 0; _$jscoverage['application.js'][440] = 0; _$jscoverage['application.js'][441] = 0; _$jscoverage['application.js'][442] = 0; _$jscoverage['application.js'][443] = 0; _$jscoverage['application.js'][444] = 0; _$jscoverage['application.js'][458] = 0; _$jscoverage['application.js'][459] = 0; _$jscoverage['application.js'][460] = 0; _$jscoverage['application.js'][461] = 0; _$jscoverage['application.js'][462] = 0; _$jscoverage['application.js'][464] = 0; _$jscoverage['application.js'][469] = 0; _$jscoverage['application.js'][482] = 0; _$jscoverage['application.js'][483] = 0; _$jscoverage['application.js'][490] = 0; _$jscoverage['application.js'][491] = 0; _$jscoverage['application.js'][495] = 0; _$jscoverage['application.js'][498] = 0; _$jscoverage['application.js'][501] = 0; _$jscoverage['application.js'][504] = 0; _$jscoverage['application.js'][509] = 0; _$jscoverage['application.js'][512] = 0; _$jscoverage['application.js'][513] = 0; _$jscoverage['application.js'][520] = 0; _$jscoverage['application.js'][524] = 0; _$jscoverage['application.js'][525] = 0; _$jscoverage['application.js'][527] = 0; } _$jscoverage['application.js'][12]++; var connect = require("connect"), Router = require("./router"), methods = Router.methods.concat("del", "all"), middleware = require("./middleware"), debug = require("debug")("express:application"), View = require("./view"), url = require("url"), utils = connect.utils, path = require("path"), http = require("http"), join = path.join, fs = require("fs"); _$jscoverage['application.js'][29]++; var app = exports = module.exports = {}; _$jscoverage['application.js'][41]++; app.init = (function () { _$jscoverage['application.js'][42]++; var self = this; _$jscoverage['application.js'][43]++; this.cache = {}; _$jscoverage['application.js'][44]++; this.settings = {}; _$jscoverage['application.js'][45]++; this.engines = {}; _$jscoverage['application.js'][46]++; this.viewCallbacks = []; _$jscoverage['application.js'][47]++; this.defaultConfiguration(); _$jscoverage['application.js'][50]++; methods.forEach((function (method) { _$jscoverage['application.js'][51]++; self.lookup[method] = (function (path) { _$jscoverage['application.js'][52]++; return self._router.lookup(method, path); }); _$jscoverage['application.js'][55]++; self.remove[method] = (function (path) { _$jscoverage['application.js'][56]++; return self._router.lookup(method, path).remove(); }); })); _$jscoverage['application.js'][61]++; self.lookup.del = self.lookup["delete"]; _$jscoverage['application.js'][62]++; self.remove.del = self.remove["delete"]; }); _$jscoverage['application.js'][71]++; app.defaultConfiguration = (function () { _$jscoverage['application.js'][72]++; var self = this; _$jscoverage['application.js'][75]++; this.set("env", process.env.NODE_ENV || "development"); _$jscoverage['application.js'][76]++; debug("booting in %s mode", this.get("env")); _$jscoverage['application.js'][79]++; this.use(connect.query()); _$jscoverage['application.js'][80]++; this.use(middleware.init(this)); _$jscoverage['application.js'][83]++; this.locals = (function (obj) { _$jscoverage['application.js'][84]++; for (var key in obj) { _$jscoverage['application.js'][84]++; self.locals[key] = obj[key]; } _$jscoverage['application.js'][85]++; return self; }); _$jscoverage['application.js'][89]++; this.locals.use = (function (fn) { _$jscoverage['application.js'][90]++; if (3 == fn.length) { _$jscoverage['application.js'][91]++; self.viewCallbacks.push(fn); } else { _$jscoverage['application.js'][93]++; self.viewCallbacks.push((function (req, res, done) { _$jscoverage['application.js'][94]++; fn(req, res); _$jscoverage['application.js'][95]++; done(); })); } _$jscoverage['application.js'][98]++; return this; }); _$jscoverage['application.js'][102]++; this._router = new Router(this); _$jscoverage['application.js'][103]++; this.routes = this._router.routes; _$jscoverage['application.js'][104]++; this.__defineGetter__("router", (function () { _$jscoverage['application.js'][105]++; this._usedRouter = true; _$jscoverage['application.js'][106]++; this._router.caseSensitive = this.enabled("case sensitive routing"); _$jscoverage['application.js'][107]++; this._router.strict = this.enabled("strict routing"); _$jscoverage['application.js'][108]++; return this._router.middleware; })); _$jscoverage['application.js'][112]++; this.locals.settings = this.settings; _$jscoverage['application.js'][115]++; this.configure("development", (function () { _$jscoverage['application.js'][116]++; this.set("json spaces", 2); })); _$jscoverage['application.js'][119]++; this.configure("production", (function () { _$jscoverage['application.js'][120]++; this.enable("view cache"); })); }); _$jscoverage['application.js'][132]++; app.remove = (function (path) { _$jscoverage['application.js'][133]++; return this._router.lookup("all", path).remove(); }); _$jscoverage['application.js'][145]++; app.lookup = (function (path) { _$jscoverage['application.js'][146]++; return this._router.lookup("all", path); }); _$jscoverage['application.js'][159]++; app.use = (function (route, fn) { _$jscoverage['application.js'][160]++; var app, home, handle; _$jscoverage['application.js'][163]++; if ("string" != typeof route) { _$jscoverage['application.js'][163]++; fn = route, route = "/"; } _$jscoverage['application.js'][166]++; if (fn.handle && fn.set) { _$jscoverage['application.js'][166]++; app = fn; } _$jscoverage['application.js'][169]++; if (app) { _$jscoverage['application.js'][170]++; app.route = route; _$jscoverage['application.js'][171]++; fn = (function (req, res, next) { _$jscoverage['application.js'][172]++; var orig = req.app; _$jscoverage['application.js'][173]++; app.handle(req, res, (function (err) { _$jscoverage['application.js'][174]++; req.app = res.app = orig; _$jscoverage['application.js'][175]++; next(err); })); }); } _$jscoverage['application.js'][180]++; debug("use %s %s", route, fn.name || "unnamed"); _$jscoverage['application.js'][181]++; connect.proto.use.call(this, route, fn); _$jscoverage['application.js'][184]++; if (app) { _$jscoverage['application.js'][185]++; app.parent = this; _$jscoverage['application.js'][186]++; app.emit("mount", this); } _$jscoverage['application.js'][189]++; return this; }); _$jscoverage['application.js'][209]++; app.engine = (function (ext, fn) { _$jscoverage['application.js'][210]++; if ("." != ext[0]) { _$jscoverage['application.js'][210]++; ext = "." + ext; } _$jscoverage['application.js'][211]++; this.engines[ext] = fn; _$jscoverage['application.js'][212]++; return this; }); _$jscoverage['application.js'][274]++; app.param = (function (name, fn) { _$jscoverage['application.js'][275]++; var self = this, fns = [].slice.call(arguments, 1); _$jscoverage['application.js'][279]++; if (Array.isArray(name)) { _$jscoverage['application.js'][280]++; name.forEach((function (name) { _$jscoverage['application.js'][281]++; fns.forEach((function (fn) { _$jscoverage['application.js'][282]++; self.param(name, fn); })); })); } else { _$jscoverage['application.js'][286]++; if ("function" == typeof name) { _$jscoverage['application.js'][287]++; this._router.param(name); } else { _$jscoverage['application.js'][290]++; if (":" == name[0]) { _$jscoverage['application.js'][290]++; name = name.substr(1); } _$jscoverage['application.js'][291]++; fns.forEach((function (fn) { _$jscoverage['application.js'][292]++; self._router.param(name, fn); })); } } _$jscoverage['application.js'][296]++; return this; }); _$jscoverage['application.js'][309]++; app.set = (function (setting, val) { _$jscoverage['application.js'][310]++; if (1 == arguments.length) { _$jscoverage['application.js'][311]++; if (this.settings.hasOwnProperty(setting)) { _$jscoverage['application.js'][312]++; return this.settings[setting]; } else { _$jscoverage['application.js'][313]++; if (this.parent) { _$jscoverage['application.js'][314]++; return this.parent.set(setting); } } } else { _$jscoverage['application.js'][317]++; this.settings[setting] = val; _$jscoverage['application.js'][318]++; return this; } }); _$jscoverage['application.js'][331]++; app.path = (function () { _$jscoverage['application.js'][332]++; return this.parent? this.parent.path() + this.route: ""; }); _$jscoverage['application.js'][345]++; app.enabled = (function (setting) { _$jscoverage['application.js'][346]++; return ! ! this.set(setting); }); _$jscoverage['application.js'][357]++; app.disabled = (function (setting) { _$jscoverage['application.js'][358]++; return ! this.set(setting); }); _$jscoverage['application.js'][369]++; app.enable = (function (setting) { _$jscoverage['application.js'][370]++; return this.set(setting, true); }); _$jscoverage['application.js'][381]++; app.disable = (function (setting) { _$jscoverage['application.js'][382]++; return this.set(setting, false); }); _$jscoverage['application.js'][411]++; app.configure = (function (env, fn) { _$jscoverage['application.js'][412]++; var envs = "all", args = [].slice.call(arguments); _$jscoverage['application.js'][414]++; fn = args.pop(); _$jscoverage['application.js'][415]++; if (args.length) { _$jscoverage['application.js'][415]++; envs = args; } _$jscoverage['application.js'][416]++; if ("all" == envs || ~ envs.indexOf(this.settings.env)) { _$jscoverage['application.js'][416]++; fn.call(this); } _$jscoverage['application.js'][417]++; return this; }); _$jscoverage['application.js'][430]++; app.listen = (function () { _$jscoverage['application.js'][431]++; var server = http.createServer(this); _$jscoverage['application.js'][432]++; return server.listen.apply(server, arguments); }); _$jscoverage['application.js'][439]++; methods.forEach((function (method) { _$jscoverage['application.js'][440]++; app[method] = (function (path) { _$jscoverage['application.js'][441]++; if ("get" == method && 1 == arguments.length) { _$jscoverage['application.js'][441]++; return this.set(path); } _$jscoverage['application.js'][442]++; var args = [method].concat([].slice.call(arguments)); _$jscoverage['application.js'][443]++; if (! this._usedRouter) { _$jscoverage['application.js'][443]++; this.use(this.router); } _$jscoverage['application.js'][444]++; return this._router.route.apply(this._router, args); }); })); _$jscoverage['application.js'][458]++; app.all = (function (path) { _$jscoverage['application.js'][459]++; var args = arguments; _$jscoverage['application.js'][460]++; methods.forEach((function (method) { _$jscoverage['application.js'][461]++; if ("all" == method || "del" == method) { _$jscoverage['application.js'][461]++; return; } _$jscoverage['application.js'][462]++; app[method].apply(this, args); }), this); _$jscoverage['application.js'][464]++; return this; }); _$jscoverage['application.js'][469]++; app.del = app["delete"]; _$jscoverage['application.js'][482]++; app.render = (function (name, options, fn) { _$jscoverage['application.js'][483]++; var self = this, opts = {}, cache = this.cache, engines = this.engines, view; _$jscoverage['application.js'][490]++; if ("function" == typeof options) { _$jscoverage['application.js'][491]++; fn = options, options = {}; } _$jscoverage['application.js'][495]++; utils.merge(opts, this.locals); _$jscoverage['application.js'][498]++; if (options.locals) { _$jscoverage['application.js'][498]++; utils.merge(opts, options.locals); } _$jscoverage['application.js'][501]++; utils.merge(opts, options); _$jscoverage['application.js'][504]++; opts.cache = null == opts.cache? this.enabled("view cache"): opts.cache; _$jscoverage['application.js'][509]++; if (opts.cache) { _$jscoverage['application.js'][509]++; view = cache[name]; } _$jscoverage['application.js'][512]++; if (! view) { _$jscoverage['application.js'][513]++; view = new View(name, {defaultEngine: this.get("view engine"), root: this.get("views") || process.cwd() + "/views", engines: engines}); _$jscoverage['application.js'][520]++; if (opts.cache) { _$jscoverage['application.js'][520]++; cache[name] = view; } } _$jscoverage['application.js'][524]++; try { _$jscoverage['application.js'][525]++; view.render(opts, fn); } catch (err) { _$jscoverage['application.js'][527]++; fn(err); } }); _$jscoverage['application.js'].source = ["","/*!"," * Express - proto"," * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>"," * MIT Licensed"," */","","/**"," * Module dependencies."," */","","var connect = require('connect')"," , Router = require('./router')"," , methods = Router.methods.concat('del', 'all')"," , middleware = require('./middleware')"," , debug = require('debug')('express:application')"," , View = require('./view')"," , url = require('url')"," , utils = connect.utils"," , path = require('path')"," , http = require('http')"," , join = path.join"," , fs = require('fs');","","/**"," * Application prototype."," */","","var app = exports = module.exports = {};","","/**"," * Initialize the server."," *"," * - setup default configuration"," * - setup default middleware"," * - setup route reflection methods"," *"," * @api private"," */","","app.init = function(){"," var self = this;"," this.cache = {};"," this.settings = {};"," this.engines = {};"," this.viewCallbacks = [];"," this.defaultConfiguration();",""," // route reflection methods"," methods.forEach(function(method){"," self.lookup[method] = function(path){"," return self._router.lookup(method, path);"," };",""," self.remove[method] = function(path){"," return self._router.lookup(method, path).remove();"," };"," });",""," // del -> delete"," self.lookup.del = self.lookup.delete;"," self.remove.del = self.remove.delete;","};","","/**"," * Initialize application configuration."," *"," * @api private"," */","","app.defaultConfiguration = function(){"," var self = this;",""," // default settings"," this.set('env', process.env.NODE_ENV || 'development');"," debug('booting in %s mode', this.get('env'));",""," // implicit middleware"," this.use(connect.query());"," this.use(middleware.init(this));",""," // app locals"," this.locals = function(obj){"," for (var key in obj) self.locals[key] = obj[key];"," return self;"," };",""," // response locals"," this.locals.use = function(fn){"," if (3 == fn.length) {"," self.viewCallbacks.push(fn);"," } else {"," self.viewCallbacks.push(function(req, res, done){"," fn(req, res);"," done();"," });"," }"," return this;"," };",""," // router"," this._router = new Router(this);"," this.routes = this._router.routes;"," this.__defineGetter__('router', function(){"," this._usedRouter = true;"," this._router.caseSensitive = this.enabled('case sensitive routing');"," this._router.strict = this.enabled('strict routing');"," return this._router.middleware;"," });",""," // default locals"," this.locals.settings = this.settings;",""," // default configuration"," this.configure('development', function(){"," this.set('json spaces', 2);"," });",""," this.configure('production', function(){"," this.enable('view cache');"," });","};","","/**"," * Remove routes matching the given `path`."," *"," * @param {Route} path"," * @return {Boolean}"," * @api public"," */","","app.remove = function(path){"," return this._router.lookup('all', path).remove();","};","","/**"," * Lookup routes defined with a path"," * equivalent to `path`."," *"," * @param {String} path"," * @return {Array}"," * @api public"," */","","app.lookup = function(path){"," return this._router.lookup('all', path);","};","","/**"," * Proxy `connect#use()` to apply settings to"," * mounted applications."," *"," * @param {String|Function|Server} route"," * @param {Function|Server} fn"," * @return {app} for chaining"," * @api public"," */","","app.use = function(route, fn){"," var app, home, handle;",""," // default route to '/'"," if ('string' != typeof route) fn = route, route = '/';",""," // express app"," if (fn.handle && fn.set) app = fn;",""," // restore .app property on req and res"," if (app) {"," app.route = route;"," fn = function(req, res, next) {"," var orig = req.app;"," app.handle(req, res, function(err){"," req.app = res.app = orig;"," next(err);"," });"," };"," }",""," debug('use %s %s', route, fn.name || 'unnamed');"," connect.proto.use.call(this, route, fn);",""," // mounted an app"," if (app) {"," app.parent = this;"," app.emit('mount', this);"," }",""," return this;","};","","/**"," * Register the given template engine callback `fn`"," * as `ext`. For example we may wish to map \".html\""," * files to ejs rather than using the \".ejs\" extension."," *"," * app.engine('.html', require('ejs').render);"," *"," * or"," *"," * app.engine('html', require('ejs').render);"," *"," * @param {String} ext"," * @param {Function} fn"," * @return {app} for chaining"," * @api public"," */","","app.engine = function(ext, fn){"," if ('.' != ext[0]) ext = '.' + ext;"," this.engines[ext] = fn;"," return this;","};","","/**"," * Map the given param placeholder `name`(s) to the given callback(s)."," *"," * Param mapping is used to provide pre-conditions to routes"," * which us normalized placeholders. This callback has the same"," * signature as regular middleware, for example below when \":userId\""," * is used this function will be invoked in an attempt to load the user."," *"," * app.param('userId', function(req, res, next, id){"," * User.find(id, function(err, user){"," * if (err) {"," * next(err);"," * } else if (user) {"," * req.user = user;"," * next();"," * } else {"," * next(new Error('failed to load user'));"," * }"," * });"," * });"," *"," * Passing a single function allows you to map logic"," * to the values passed to `app.param()`, for example"," * this is useful to provide coercion support in a concise manner."," *"," * The following example maps regular expressions to param values"," * ensuring that they match, otherwise passing control to the next"," * route:"," *"," * app.param(function(name, regexp){"," * if (regexp instanceof RegExp) {"," * return function(req, res, next, val){"," * var captures;"," * if (captures = regexp.exec(String(val))) {"," * req.params[name] = captures;"," * next();"," * } else {"," * next('route');"," * }"," * }"," * }"," * });"," *"," * We can now use it as shown below, where \"/commit/:commit\" expects"," * that the value for \":commit\" is at 5 or more digits. The capture"," * groups are then available as `req.params.commit` as we defined"," * in the function above."," *"," * app.param('commit', /^\\d{5,}$/);"," *"," * For more of this useful functionality take a look"," * at [express-params](http://github.com/visionmedia/express-params)."," *"," * @param {String|Array|Function} name"," * @param {Function} fn"," * @return {app} for chaining"," * @api public"," */","","app.param = function(name, fn){"," var self = this"," , fns = [].slice.call(arguments, 1);",""," // array"," if (Array.isArray(name)) {"," name.forEach(function(name){"," fns.forEach(function(fn){"," self.param(name, fn);"," });"," });"," // param logic"," } else if ('function' == typeof name) {"," this._router.param(name);"," // single"," } else {"," if (':' == name[0]) name = name.substr(1);"," fns.forEach(function(fn){"," self._router.param(name, fn);"," });"," }",""," return this;","};","","/**"," * Assign `setting` to `val`, or return `setting`'s value."," * Mounted servers inherit their parent server's settings."," *"," * @param {String} setting"," * @param {String} val"," * @return {Server|Mixed} for chaining, or the setting value"," * @api public"," */","","app.set = function(setting, val){"," if (1 == arguments.length) {"," if (this.settings.hasOwnProperty(setting)) {"," return this.settings[setting];"," } else if (this.parent) {"," return this.parent.set(setting);"," }"," } else {"," this.settings[setting] = val;"," return this;"," }","};","","/**"," * Return the app's absolute pathname"," * based on the parent(s) that have"," * mounted it."," *"," * @return {String}"," * @api private"," */","","app.path = function(){"," return this.parent"," ? this.parent.path() + this.route"," : '';","};","","/**"," * Check if `setting` is enabled."," *"," * @param {String} setting"," * @return {Boolean}"," * @api public"," */","","app.enabled = function(setting){"," return !!this.set(setting);","};","","/**"," * Check if `setting` is disabled."," *"," * @param {String} setting"," * @return {Boolean}"," * @api public"," */","","app.disabled = function(setting){"," return !this.set(setting);","};","","/**"," * Enable `setting`."," *"," * @param {String} setting"," * @return {app} for chaining"," * @api public"," */","","app.enable = function(setting){"," return this.set(setting, true);","};","","/**"," * Disable `setting`."," *"," * @param {String} setting"," * @return {app} for chaining"," * @api public"," */","","app.disable = function(setting){"," return this.set(setting, false);","};","","/**"," * Configure callback for zero or more envs,"," * when no env is specified that callback will"," * be invoked for all environments. Any combination"," * can be used multiple times, in any order desired."," *"," * Examples:"," *"," * app.configure(function(){"," * // executed for all envs"," * });"," *"," * app.configure('stage', function(){"," * // executed staging env"," * });"," *"," * app.configure('stage', 'production', function(){"," * // executed for stage and production"," * });"," *"," * @param {String} env..."," * @param {Function} fn"," * @return {app} for chaining"," * @api public"," */","","app.configure = function(env, fn){"," var envs = 'all'"," , args = [].slice.call(arguments);"," fn = args.pop();"," if (args.length) envs = args;"," if ('all' == envs || ~envs.indexOf(this.settings.env)) fn.call(this);"," return this;","};","","/**"," * Listen for connections."," *"," * This method takes the same arguments"," * as node's `http.Server#listen()`. "," *"," * @return {http.Server}"," * @api public"," */","","app.listen = function(){"," var server = http.createServer(this);"," return server.listen.apply(server, arguments);","};","","/**"," * Delegate `.VERB(...)` calls to `.route(VERB, ...)`."," */","","methods.forEach(function(method){"," app[method] = function(path){"," if ('get' == method && 1 == arguments.length) return this.set(path); "," var args = [method].concat([].slice.call(arguments));"," if (!this._usedRouter) this.use(this.router);"," return this._router.route.apply(this._router, args);"," }","});","","/**"," * Special-cased \"all\" method, applying the given route `path`,"," * middleware, and callback to _every_ HTTP method."," *"," * @param {String} path"," * @param {Function} ..."," * @return {app} for chaining"," * @api public"," */","","app.all = function(path){"," var args = arguments;"," methods.forEach(function(method){"," if ('all' == method || 'del' == method) return;"," app[method].apply(this, args);"," }, this);"," return this;","};","","// del -> delete alias","","app.del = app.delete;","","/**"," * Render the given view `name` name with `options`"," * and a callback accepting an error and the"," * rendered template string."," *"," * @param {String} name"," * @param {String|Function} options or fn"," * @param {Function} fn"," * @api public"," */","","app.render = function(name, options, fn){"," var self = this"," , opts = {}"," , cache = this.cache"," , engines = this.engines"," , view;",""," // support callback function as second arg"," if ('function' == typeof options) {"," fn = options, options = {};"," }",""," // merge app.locals"," utils.merge(opts, this.locals);",""," // merge options.locals"," if (options.locals) utils.merge(opts, options.locals);",""," // merge options"," utils.merge(opts, options);",""," // set .cache unless explicitly provided"," opts.cache = null == opts.cache"," ? this.enabled('view cache')"," : opts.cache;",""," // primed cache"," if (opts.cache) view = cache[name];",""," // view"," if (!view) {"," view = new View(name, {"," defaultEngine: this.get('view engine')"," , root: this.get('views') || process.cwd() + '/views'"," , engines: engines"," });",""," // prime the cache"," if (opts.cache) cache[name] = view;"," }",""," // render"," try {"," view.render(opts, fn);"," } catch (err) {"," fn(err);"," }","};"]; package/lib-cov/express.js000644 000765 000024 0000007700 11722507472014124 0ustar00000000 000000 /* automatically generated by JSCoverage - do not edit */ if (typeof _$jscoverage === 'undefined') _$jscoverage = {}; if (! _$jscoverage['express.js']) { _$jscoverage['express.js'] = []; _$jscoverage['express.js'][12] = 0; _$jscoverage['express.js'][25] = 0; _$jscoverage['express.js'][31] = 0; _$jscoverage['express.js'][40] = 0; _$jscoverage['express.js'][41] = 0; _$jscoverage['express.js'][42] = 0; _$jscoverage['express.js'][43] = 0; _$jscoverage['express.js'][44] = 0; _$jscoverage['express.js'][45] = 0; _$jscoverage['express.js'][46] = 0; _$jscoverage['express.js'][54] = 0; _$jscoverage['express.js'][55] = 0; _$jscoverage['express.js'][65] = 0; _$jscoverage['express.js'][66] = 0; _$jscoverage['express.js'][67] = 0; _$jscoverage['express.js'][73] = 0; _$jscoverage['express.js'][74] = 0; _$jscoverage['express.js'][80] = 0; _$jscoverage['express.js'][84] = 0; } _$jscoverage['express.js'][12]++; var http = require("http"), connect = require("connect"), proto = require("./application"), Route = require("./router/route"), Router = require("./router"), req = require("./request"), res = require("./response"), utils = connect.utils; _$jscoverage['express.js'][25]++; exports = module.exports = createApplication; _$jscoverage['express.js'][31]++; exports.version = "3.0.0alpha1-pre"; _$jscoverage['express.js'][40]++; function createApplication() { _$jscoverage['express.js'][41]++; var app = connect(); _$jscoverage['express.js'][42]++; utils.merge(app, proto); _$jscoverage['express.js'][43]++; app.request = {__proto__: req}; _$jscoverage['express.js'][44]++; app.response = {__proto__: res}; _$jscoverage['express.js'][45]++; app.init(); _$jscoverage['express.js'][46]++; return app; } _$jscoverage['express.js'][54]++; for (var key in connect.middleware) { _$jscoverage['express.js'][55]++; Object.defineProperty(exports, key, Object.getOwnPropertyDescriptor(connect.middleware, key)); } _$jscoverage['express.js'][65]++; exports.application = proto; _$jscoverage['express.js'][66]++; exports.request = req; _$jscoverage['express.js'][67]++; exports.response = res; _$jscoverage['express.js'][73]++; exports.Route = Route; _$jscoverage['express.js'][74]++; exports.Router = Router; _$jscoverage['express.js'][80]++; exports.methods = require("./router/methods"); _$jscoverage['express.js'][84]++; exports.errorHandler.title = "Express"; _$jscoverage['express.js'].source = ["","/*!"," * Express"," * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>"," * MIT Licensed"," */","","/**"," * Module dependencies."," */","","var http = require('http')"," , connect = require('connect')"," , proto = require('./application')"," , Route = require('./router/route')"," , Router = require('./router')"," , req = require('./request')"," , res = require('./response')"," , utils = connect.utils;","","/**"," * Expose `createApplication()`."," */","","exports = module.exports = createApplication;","","/**"," * Framework version."," */","","exports.version = '3.0.0alpha1-pre';","","/**"," * Create an express application."," *"," * @return {Function}"," * @api public"," */","","function createApplication() {"," var app = connect();"," utils.merge(app, proto);"," app.request = { __proto__: req };"," app.response = { __proto__: res };"," app.init();"," return app;","}","","/**"," * Expose connect.middleware as express.*"," * for example `express.logger` etc. "," */","","for (var key in connect.middleware) {"," Object.defineProperty("," exports"," , key"," , Object.getOwnPropertyDescriptor(connect.middleware, key));","}","","/**"," * Expose the prototypes."," */","","exports.application = proto;","exports.request = req;","exports.response = res;","","/**"," * Expose constructors."," */","","exports.Route = Route;","exports.Router = Router;","","/**"," * Expose HTTP methods."," */","","exports.methods = require('./router/methods');","","// Error handler title","","exports.errorHandler.title = 'Express';",""]; package/lib-cov/middleware.js000644 000765 000024 0000005103 11722507472014543 0ustar00000000 000000 /* automatically generated by JSCoverage - do not edit */ if (typeof _$jscoverage === 'undefined') _$jscoverage = {}; if (! _$jscoverage['middleware.js']) { _$jscoverage['middleware.js'] = []; _$jscoverage['middleware.js'][18] = 0; _$jscoverage['middleware.js'][19] = 0; _$jscoverage['middleware.js'][20] = 0; _$jscoverage['middleware.js'][21] = 0; _$jscoverage['middleware.js'][22] = 0; _$jscoverage['middleware.js'][23] = 0; _$jscoverage['middleware.js'][24] = 0; _$jscoverage['middleware.js'][25] = 0; _$jscoverage['middleware.js'][27] = 0; _$jscoverage['middleware.js'][28] = 0; _$jscoverage['middleware.js'][30] = 0; _$jscoverage['middleware.js'][31] = 0; _$jscoverage['middleware.js'][32] = 0; _$jscoverage['middleware.js'][35] = 0; } _$jscoverage['middleware.js'][18]++; exports.init = (function (app) { _$jscoverage['middleware.js'][19]++; return (function (req, res, next) { _$jscoverage['middleware.js'][20]++; var charset; _$jscoverage['middleware.js'][21]++; res.setHeader("X-Powered-By", "Express"); _$jscoverage['middleware.js'][22]++; req.app = res.app = app; _$jscoverage['middleware.js'][23]++; req.res = res; _$jscoverage['middleware.js'][24]++; res.req = req; _$jscoverage['middleware.js'][25]++; req.next = next; _$jscoverage['middleware.js'][27]++; req.__proto__ = app.request; _$jscoverage['middleware.js'][28]++; res.__proto__ = app.response; _$jscoverage['middleware.js'][30]++; res.locals = (function (obj) { _$jscoverage['middleware.js'][31]++; for (var key in obj) { _$jscoverage['middleware.js'][31]++; res.locals[key] = obj[key]; } _$jscoverage['middleware.js'][32]++; return res; }); _$jscoverage['middleware.js'][35]++; next(); }); }); _$jscoverage['middleware.js'].source = ["","/*!"," * Express - middleware - init"," * Copyright(c) 2010-2011 TJ Holowaychuk <tj@vision-media.ca>"," * MIT Licensed"," */","","/**"," * Initialization middleware, exposing the"," * request and response to eachother, as well"," * as defaulting the X-Powered-By header field."," *"," * @param {Function} app"," * @return {Function}"," * @api private"," */","","exports.init = function(app){"," return function(req, res, next){"," var charset;"," res.setHeader('X-Powered-By', 'Express');"," req.app = res.app = app;"," req.res = res;"," res.req = req;"," req.next = next;",""," req.__proto__ = app.request;"," res.__proto__ = app.response;",""," res.locals = function(obj){"," for (var key in obj) res.locals[key] = obj[key];"," return res;"," };",""," next();"," }","};"]; package/lib-cov/request.js000644 000765 000024 0000040367 11722507472014131 0ustar00000000 000000 /* automatically generated by JSCoverage - do not edit */ if (typeof _$jscoverage === 'undefined') _$jscoverage = {}; if (! _$jscoverage['request.js']) { _$jscoverage['request.js'] = []; _$jscoverage['request.js'][12] = 0; _$jscoverage['request.js'][22] = 0; _$jscoverage['request.js'][49] = 0; _$jscoverage['request.js'][50] = 0; _$jscoverage['request.js'][53] = 0; _$jscoverage['request.js'][56] = 0; _$jscoverage['request.js'][86] = 0; _$jscoverage['request.js'][87] = 0; _$jscoverage['request.js'][99] = 0; _$jscoverage['request.js'][100] = 0; _$jscoverage['request.js'][101] = 0; _$jscoverage['request.js'][115] = 0; _$jscoverage['request.js'][116] = 0; _$jscoverage['request.js'][117] = 0; _$jscoverage['request.js'][141] = 0; _$jscoverage['request.js'][142] = 0; _$jscoverage['request.js'][143] = 0; _$jscoverage['request.js'][161] = 0; _$jscoverage['request.js'][162] = 0; _$jscoverage['request.js'][163] = 0; _$jscoverage['request.js'][167] = 0; _$jscoverage['request.js'][185] = 0; _$jscoverage['request.js'][186] = 0; _$jscoverage['request.js'][187] = 0; _$jscoverage['request.js'][191] = 0; _$jscoverage['request.js'][213] = 0; _$jscoverage['request.js'][215] = 0; _$jscoverage['request.js'][218] = 0; _$jscoverage['request.js'][221] = 0; _$jscoverage['request.js'][225] = 0; _$jscoverage['request.js'][227] = 0; _$jscoverage['request.js'][267] = 0; _$jscoverage['request.js'][268] = 0; _$jscoverage['request.js'][269] = 0; _$jscoverage['request.js'][270] = 0; _$jscoverage['request.js'][271] = 0; _$jscoverage['request.js'][272] = 0; _$jscoverage['request.js'][273] = 0; _$jscoverage['request.js'][274] = 0; _$jscoverage['request.js'][275] = 0; _$jscoverage['request.js'][276] = 0; _$jscoverage['request.js'][277] = 0; _$jscoverage['request.js'][279] = 0; _$jscoverage['request.js'][294] = 0; _$jscoverage['request.js'][295] = 0; _$jscoverage['request.js'][296] = 0; _$jscoverage['request.js'][310] = 0; _$jscoverage['request.js'][311] = 0; _$jscoverage['request.js'][324] = 0; _$jscoverage['request.js'][325] = 0; _$jscoverage['request.js'][338] = 0; _$jscoverage['request.js'][339] = 0; _$jscoverage['request.js'][351] = 0; _$jscoverage['request.js'][352] = 0; _$jscoverage['request.js'][364] = 0; _$jscoverage['request.js'][365] = 0; _$jscoverage['request.js'][375] = 0; _$jscoverage['request.js'][376] = 0; _$jscoverage['request.js'][377] = 0; } _$jscoverage['request.js'][12]++; var http = require("http"), utils = require("./utils"), connect = require("connect"), parse = require("url").parse, mime = require("mime"); _$jscoverage['request.js'][22]++; var req = exports = module.exports = {__proto__: http.IncomingMessage.prototype}; _$jscoverage['request.js'][49]++; req.get = (function (name) { _$jscoverage['request.js'][50]++; switch (name = name.toLowerCase()) { case "referer": case "referrer": _$jscoverage['request.js'][53]++; return this.headers.referrer || this.headers.referer; default: _$jscoverage['request.js'][56]++; return this.headers[name]; } }); _$jscoverage['request.js'][86]++; req.accepts = (function (type) { _$jscoverage['request.js'][87]++; return utils.accepts(type, this.get("Accept")); }); _$jscoverage['request.js'][99]++; req.acceptsCharset = (function (charset) { _$jscoverage['request.js'][100]++; var accepted = this.acceptedCharsets; _$jscoverage['request.js'][101]++; return accepted.length? ~ accepted.indexOf(charset): true; }); _$jscoverage['request.js'][115]++; req.acceptsLanguage = (function (lang) { _$jscoverage['request.js'][116]++; var accepted = this.acceptedLanguages; _$jscoverage['request.js'][117]++; return accepted.length? ~ accepted.indexOf(lang): true; }); _$jscoverage['request.js'][141]++; req.__defineGetter__("accepted", (function () { _$jscoverage['request.js'][142]++; var accept = this.get("Accept"); _$jscoverage['request.js'][143]++; return accept? utils.parseAccept(accept): []; })); _$jscoverage['request.js'][161]++; req.__defineGetter__("acceptedLanguages", (function () { _$jscoverage['request.js'][162]++; var accept = this.get("Accept-Language"); _$jscoverage['request.js'][163]++; return accept? utils.parseQuality(accept).map((function (obj) { _$jscoverage['request.js'][167]++; return obj.value; })): []; })); _$jscoverage['request.js'][185]++; req.__defineGetter__("acceptedCharsets", (function () { _$jscoverage['request.js'][186]++; var accept = this.get("Accept-Charset"); _$jscoverage['request.js'][187]++; return accept? utils.parseQuality(accept).map((function (obj) { _$jscoverage['request.js'][191]++; return obj.value; })): []; })); _$jscoverage['request.js'][213]++; req.param = (function (name, defaultValue) { _$jscoverage['request.js'][215]++; if (this.body && undefined !== this.body[name]) { _$jscoverage['request.js'][215]++; return this.body[name]; } _$jscoverage['request.js'][218]++; if (this.params && this.params.hasOwnProperty(name) && undefined !== this.params[name]) { _$jscoverage['request.js'][221]++; return this.params[name]; } _$jscoverage['request.js'][225]++; if (undefined !== this.query[name]) { _$jscoverage['request.js'][225]++; return this.query[name]; } _$jscoverage['request.js'][227]++; return defaultValue; }); _$jscoverage['request.js'][267]++; req.is = (function (type) { _$jscoverage['request.js'][268]++; var ct = this.get("Content-Type"); _$jscoverage['request.js'][269]++; if (! ct) { _$jscoverage['request.js'][269]++; return false; } _$jscoverage['request.js'][270]++; ct = ct.split(";")[0]; _$jscoverage['request.js'][271]++; if (! ~ type.indexOf("/")) { _$jscoverage['request.js'][271]++; type = mime.lookup(type); } _$jscoverage['request.js'][272]++; if (~ type.indexOf("*")) { _$jscoverage['request.js'][273]++; type = type.split("/"); _$jscoverage['request.js'][274]++; ct = ct.split("/"); _$jscoverage['request.js'][275]++; if ("*" == type[0] && type[1] == ct[1]) { _$jscoverage['request.js'][275]++; return true; } _$jscoverage['request.js'][276]++; if ("*" == type[1] && type[0] == ct[0]) { _$jscoverage['request.js'][276]++; return true; } _$jscoverage['request.js'][277]++; return false; } _$jscoverage['request.js'][279]++; return ! ! ~ ct.indexOf(type); }); _$jscoverage['request.js'][294]++; req.__defineGetter__("protocol", (function (trustProxy) { _$jscoverage['request.js'][295]++; var trustProxy = this.app.settings["trust proxy"]; _$jscoverage['request.js'][296]++; return this.secure? "https": trustProxy? (this.get("X-Forwarded-Proto") || "http"): "http"; })); _$jscoverage['request.js'][310]++; req.__defineGetter__("secure", (function () { _$jscoverage['request.js'][311]++; return this.connection.encrypted; })); _$jscoverage['request.js'][324]++; req.__defineGetter__("subdomains", (function () { _$jscoverage['request.js'][325]++; return this.get("Host").split(".").slice(0, -2).reverse(); })); _$jscoverage['request.js'][338]++; req.__defineGetter__("path", (function () { _$jscoverage['request.js'][339]++; return parse(this.url).pathname; })); _$jscoverage['request.js'][351]++; req.__defineGetter__("fresh", (function () { _$jscoverage['request.js'][352]++; return ! this.stale; })); _$jscoverage['request.js'][364]++; req.__defineGetter__("stale", (function () { _$jscoverage['request.js'][365]++; return connect.utils.modified(this, this.res); })); _$jscoverage['request.js'][375]++; req.__defineGetter__("xhr", (function () { _$jscoverage['request.js'][376]++; var val = this.get("X-Requested-With") || ""; _$jscoverage['request.js'][377]++; return "xmlhttprequest" == val.toLowerCase(); })); _$jscoverage['request.js'].source = ["","/*!"," * Express - request"," * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>"," * MIT Licensed"," */","","/**"," * Module dependencies."," */","","var http = require('http')"," , utils = require('./utils')"," , connect = require('connect')"," , parse = require('url').parse"," , mime = require('mime');","","/**"," * Request prototype."," */","","var req = exports = module.exports = {"," __proto__: http.IncomingMessage.prototype","};","","/**"," * Return request header."," *"," * The `Referrer` header field is special-cased,"," * both `Referrer` and `Referer` will yield are"," * interchangeable."," *"," * Examples:"," *"," * req.get('Content-Type');"," * // => \"text/plain\""," * "," * req.get('content-type');"," * // => \"text/plain\""," * "," * req.get('Something');"," * // => undefined"," * "," * @param {String} name"," * @return {String} "," * @api public"," */","","req.get = function(name){"," switch (name = name.toLowerCase()) {"," case 'referer':"," case 'referrer':"," return this.headers.referrer"," || this.headers.referer;"," default:"," return this.headers[name];"," }","};","","/**"," * Check if the given `type` is acceptable,"," * otherwise you should respond with 406 \"Not Acceptable\"."," *"," * Examples:"," * "," * // Accept: text/html"," * req.accepts('html');"," * // => true"," *"," * // Accept: text/*; application/json"," * req.accepts('html');"," * req.accepts('text/html');"," * req.accepts('text/plain');"," * req.accepts('application/json');"," * // => true"," *"," * req.accepts('image/png');"," * req.accepts('png');"," * // => false"," *"," * @param {String} type"," * @return {Boolean}"," * @api public"," */","","req.accepts = function(type){"," return utils.accepts(type, this.get('Accept'));","};","","/**"," * Check if the given `charset` is acceptable,"," * otherwise you should respond with 406 \"Not Acceptable\"."," *"," * @param {String} charset"," * @return {Boolean}"," * @api public"," */","","req.acceptsCharset = function(charset){"," var accepted = this.acceptedCharsets;"," return accepted.length"," ? ~accepted.indexOf(charset)"," : true;","};","","/**"," * Check if the given `lang` is acceptable,"," * otherwise you should respond with 406 \"Not Acceptable\"."," *"," * @param {String} lang"," * @return {Boolean}"," * @api public"," */","","req.acceptsLanguage = function(lang){"," var accepted = this.acceptedLanguages;"," return accepted.length"," ? ~accepted.indexOf(lang)"," : true;","};","","/**"," * Return an array of Accepted media types"," * ordered from highest quality to lowest."," *"," * Examples:"," *"," * [ { value: 'application/json',"," * quality: 1,"," * type: 'application',"," * subtype: 'json' },"," * { value: 'text/html',"," * quality: 0.5,"," * type: 'text',"," * subtype: 'html' } ]"," *"," * @return {Array}"," * @api public"," */","","req.__defineGetter__('accepted', function(){"," var accept = this.get('Accept');"," return accept"," ? utils.parseAccept(accept)"," : [];","});","","/**"," * Return an array of Accepted languages"," * ordered from highest quality to lowest."," *"," * Examples:"," *"," * Accept-Language: en;q=.5, en-us"," * ['en-us', 'en']"," *"," * @return {Array}"," * @api public"," */","","req.__defineGetter__('acceptedLanguages', function(){"," var accept = this.get('Accept-Language');"," return accept"," ? utils"," .parseQuality(accept)"," .map(function(obj){"," return obj.value;"," })"," : [];","});","","/**"," * Return an array of Accepted charsets"," * ordered from highest quality to lowest."," *"," * Examples:"," *"," * Accept-Charset: iso-8859-5;q=.2, unicode-1-1;q=0.8"," * ['unicode-1-1', 'iso-8859-5']"," *"," * @return {Array}"," * @api public"," */","","req.__defineGetter__('acceptedCharsets', function(){"," var accept = this.get('Accept-Charset');"," return accept"," ? utils"," .parseQuality(accept)"," .map(function(obj){"," return obj.value;"," })"," : [];","});","","/**"," * Return the value of param `name` when present or `defaultValue`."," *"," * - Checks body params, ex: id=12, {\"id\":12}"," * - Checks route placeholders, ex: _/user/:id_"," * - Checks query string params, ex: ?id=12"," *"," * To utilize request bodies, `req.body`"," * should be an object. This can be done by using"," * the `connect.bodyParser()` middleware."," *"," * @param {String} name"," * @param {Mixed} defaultValue"," * @return {String}"," * @api public"," */","","req.param = function(name, defaultValue){"," // req.body"," if (this.body && undefined !== this.body[name]) return this.body[name];",""," // route params"," if (this.params"," && this.params.hasOwnProperty(name)"," && undefined !== this.params[name]) {"," return this.params[name]; "," }",""," // query-string"," if (undefined !== this.query[name]) return this.query[name]; ",""," return defaultValue;","};","","/**"," * Check if the incoming request contains the \"Content-Type\" "," * header field, and it contains the give mime `type`."," *"," * Examples:"," *"," * // With Content-Type: text/html; charset=utf-8"," * req.is('html');"," * req.is('text/html');"," * req.is('text/*');"," * // => true"," * "," * // When Content-Type is application/json"," * req.is('json');"," * req.is('application/json');"," * req.is('application/*');"," * // => true"," * "," * req.is('html');"," * // => false"," * "," * Now within our route callbacks, we can use to to assert content types"," * such as \"image/jpeg\", \"image/png\", etc."," * "," * app.post('/image/upload', function(req, res, next){"," * if (req.is('image/*')) {"," * // do something"," * } else {"," * next();"," * }"," * });"," * "," * @param {String} type"," * @return {Boolean}"," * @api public"," */","","req.is = function(type){"," var ct = this.get('Content-Type');"," if (!ct) return false;"," ct = ct.split(';')[0];"," if (!~type.indexOf('/')) type = mime.lookup(type);"," if (~type.indexOf('*')) {"," type = type.split('/');"," ct = ct.split('/');"," if ('*' == type[0] && type[1] == ct[1]) return true;"," if ('*' == type[1] && type[0] == ct[0]) return true;"," return false;"," }"," return !! ~ct.indexOf(type);","};","","/**"," * Return the protocol string \"http\" or \"https\""," * when requested with TLS. When the \"trust proxy\" "," * setting is enabled the \"X-Forwarded-Proto\" header"," * field will be trusted. If you're running behind"," * a reverse proxy that supplies https for you this"," * may be enabled."," *"," * @return {String}"," * @api public"," */","","req.__defineGetter__('protocol', function(trustProxy){"," var trustProxy = this.app.settings['trust proxy'];"," return this.secure"," ? 'https'"," : trustProxy"," ? (this.get('X-Forwarded-Proto') || 'http')"," : 'http';","});","","/**"," * Short-hand for `req.connection.encrypted`."," *"," * @return {Boolean}"," * @api public"," */","","req.__defineGetter__('secure', function(){"," return this.connection.encrypted;","});","","/**"," * Return subdomains as an array."," *"," * For example \"tobi.ferrets.example.com\""," * would provide `[\"ferrets\", \"tobi\"]`."," *"," * @return {Array}"," * @api public"," */","","req.__defineGetter__('subdomains', function(){"," return this.get('Host')"," .split('.')"," .slice(0, -2)"," .reverse();","});","","/**"," * Short-hand for `require('url').parse(req.url).pathname`."," *"," * @return {String}"," * @api public"," */","","req.__defineGetter__('path', function(){"," return parse(this.url).pathname;","});","","/**"," * Check if the request is fresh, aka"," * Last-Modified and/or the ETag"," * still match."," *"," * @return {Boolean}"," * @api public"," */","","req.__defineGetter__('fresh', function(){"," return ! this.stale;","});","","/**"," * Check if the request is stale, aka"," * \"Last-Modified\" and / or the \"ETag\" for the"," * resource has changed."," *"," * @return {Boolean}"," * @api public"," */","","req.__defineGetter__('stale', function(){"," return connect.utils.modified(this, this.res);","});","","/**"," * Check if the request was an _XMLHttpRequest_."," *"," * @return {Boolean}"," * @api public"," */","","req.__defineGetter__('xhr', function(){"," var val = this.get('X-Requested-With') || '';"," return 'xmlhttprequest' == val.toLowerCase();","});"]; package/lib-cov/response.js000644 000765 000024 0000111563 11722507472014274 0ustar00000000 000000 /* automatically generated by JSCoverage - do not edit */ if (typeof _$jscoverage === 'undefined') _$jscoverage = {}; if (! _$jscoverage['response.js']) { _$jscoverage['response.js'] = []; _$jscoverage['response.js'][12] = 0; _$jscoverage['response.js'][28] = 0; _$jscoverage['response.js'][40] = 0; _$jscoverage['response.js'][41] = 0; _$jscoverage['response.js'][42] = 0; _$jscoverage['response.js'][58] = 0; _$jscoverage['response.js'][59] = 0; _$jscoverage['response.js'][60] = 0; _$jscoverage['response.js'][61] = 0; _$jscoverage['response.js'][62] = 0; _$jscoverage['response.js'][82] = 0; _$jscoverage['response.js'][83] = 0; _$jscoverage['response.js'][87] = 0; _$jscoverage['response.js'][88] = 0; _$jscoverage['response.js'][89] = 0; _$jscoverage['response.js'][92] = 0; _$jscoverage['response.js'][95] = 0; _$jscoverage['response.js'][96] = 0; _$jscoverage['response.js'][97] = 0; _$jscoverage['response.js'][98] = 0; _$jscoverage['response.js'][101] = 0; _$jscoverage['response.js'][102] = 0; _$jscoverage['response.js'][103] = 0; _$jscoverage['response.js'][105] = 0; _$jscoverage['response.js'][108] = 0; _$jscoverage['response.js'][109] = 0; _$jscoverage['response.js'][110] = 0; _$jscoverage['response.js'][111] = 0; _$jscoverage['response.js'][113] = 0; _$jscoverage['response.js'][115] = 0; _$jscoverage['response.js'][119] = 0; _$jscoverage['response.js'][120] = 0; _$jscoverage['response.js'][126] = 0; _$jscoverage['response.js'][127] = 0; _$jscoverage['response.js'][128] = 0; _$jscoverage['response.js'][129] = 0; _$jscoverage['response.js'][133] = 0; _$jscoverage['response.js'][134] = 0; _$jscoverage['response.js'][153] = 0; _$jscoverage['response.js'][155] = 0; _$jscoverage['response.js'][156] = 0; _$jscoverage['response.js'][157] = 0; _$jscoverage['response.js'][160] = 0; _$jscoverage['response.js'][167] = 0; _$jscoverage['response.js'][168] = 0; _$jscoverage['response.js'][170] = 0; _$jscoverage['response.js'][171] = 0; _$jscoverage['response.js'][172] = 0; _$jscoverage['response.js'][175] = 0; _$jscoverage['response.js'][198] = 0; _$jscoverage['response.js'][199] = 0; _$jscoverage['response.js'][205] = 0; _$jscoverage['response.js'][206] = 0; _$jscoverage['response.js'][207] = 0; _$jscoverage['response.js'][211] = 0; _$jscoverage['response.js'][212] = 0; _$jscoverage['response.js'][214] = 0; _$jscoverage['response.js'][219] = 0; _$jscoverage['response.js'][222] = 0; _$jscoverage['response.js'][225] = 0; _$jscoverage['response.js'][228] = 0; _$jscoverage['response.js'][230] = 0; _$jscoverage['response.js'][233] = 0; _$jscoverage['response.js'][237] = 0; _$jscoverage['response.js'][238] = 0; _$jscoverage['response.js'][255] = 0; _$jscoverage['response.js'][257] = 0; _$jscoverage['response.js'][258] = 0; _$jscoverage['response.js'][259] = 0; _$jscoverage['response.js'][262] = 0; _$jscoverage['response.js'][285] = 0; _$jscoverage['response.js'][287] = 0; _$jscoverage['response.js'][341] = 0; _$jscoverage['response.js'][342] = 0; _$jscoverage['response.js'][352] = 0; _$jscoverage['response.js'][353] = 0; _$jscoverage['response.js'][354] = 0; _$jscoverage['response.js'][361] = 0; _$jscoverage['response.js'][363] = 0; _$jscoverage['response.js'][364] = 0; _$jscoverage['response.js'][365] = 0; _$jscoverage['response.js'][366] = 0; _$jscoverage['response.js'][367] = 0; _$jscoverage['response.js'][373] = 0; _$jscoverage['response.js'][374] = 0; _$jscoverage['response.js'][375] = 0; _$jscoverage['response.js'][378] = 0; _$jscoverage['response.js'][379] = 0; _$jscoverage['response.js'][380] = 0; _$jscoverage['response.js'][382] = 0; _$jscoverage['response.js'][383] = 0; _$jscoverage['response.js'][384] = 0; _$jscoverage['response.js'][385] = 0; _$jscoverage['response.js'][388] = 0; _$jscoverage['response.js'][399] = 0; _$jscoverage['response.js'][400] = 0; _$jscoverage['response.js'][401] = 0; _$jscoverage['response.js'][404] = 0; _$jscoverage['response.js'][422] = 0; _$jscoverage['response.js'][423] = 0; _$jscoverage['response.js'][424] = 0; _$jscoverage['response.js'][426] = 0; _$jscoverage['response.js'][427] = 0; _$jscoverage['response.js'][430] = 0; _$jscoverage['response.js'][441] = 0; _$jscoverage['response.js'][442] = 0; _$jscoverage['response.js'][454] = 0; _$jscoverage['response.js'][455] = 0; _$jscoverage['response.js'][456] = 0; _$jscoverage['response.js'][471] = 0; _$jscoverage['response.js'][472] = 0; _$jscoverage['response.js'][473] = 0; _$jscoverage['response.js'][474] = 0; _$jscoverage['response.js'][475] = 0; _$jscoverage['response.js'][476] = 0; _$jscoverage['response.js'][501] = 0; _$jscoverage['response.js'][502] = 0; _$jscoverage['response.js'][503] = 0; _$jscoverage['response.js'][504] = 0; _$jscoverage['response.js'][505] = 0; _$jscoverage['response.js'][506] = 0; _$jscoverage['response.js'][507] = 0; _$jscoverage['response.js'][508] = 0; _$jscoverage['response.js'][543] = 0; _$jscoverage['response.js'][544] = 0; _$jscoverage['response.js'][551] = 0; _$jscoverage['response.js'][552] = 0; _$jscoverage['response.js'][553] = 0; _$jscoverage['response.js'][557] = 0; _$jscoverage['response.js'][560] = 0; _$jscoverage['response.js'][563] = 0; _$jscoverage['response.js'][564] = 0; _$jscoverage['response.js'][567] = 0; _$jscoverage['response.js'][568] = 0; _$jscoverage['response.js'][570] = 0; _$jscoverage['response.js'][571] = 0; _$jscoverage['response.js'][575] = 0; _$jscoverage['response.js'][576] = 0; _$jscoverage['response.js'][580] = 0; _$jscoverage['response.js'][582] = 0; _$jscoverage['response.js'][586] = 0; _$jscoverage['response.js'][591] = 0; _$jscoverage['response.js'][592] = 0; _$jscoverage['response.js'][593] = 0; _$jscoverage['response.js'][617] = 0; _$jscoverage['response.js'][618] = 0; _$jscoverage['response.js'][624] = 0; _$jscoverage['response.js'][625] = 0; _$jscoverage['response.js'][628] = 0; _$jscoverage['response.js'][630] = 0; _$jscoverage['response.js'][633] = 0; _$jscoverage['response.js'][634] = 0; _$jscoverage['response.js'][635] = 0; _$jscoverage['response.js'][639] = 0; _$jscoverage['response.js'][643] = 0; _$jscoverage['response.js'][648] = 0; _$jscoverage['response.js'][649] = 0; _$jscoverage['response.js'][650] = 0; _$jscoverage['response.js'][651] = 0; _$jscoverage['response.js'][653] = 0; _$jscoverage['response.js'][654] = 0; _$jscoverage['response.js'][655] = 0; _$jscoverage['response.js'][656] = 0; _$jscoverage['response.js'][659] = 0; _$jscoverage['response.js'][663] = 0; } _$jscoverage['response.js'][12]++; var fs = require("fs"), http = require("http"), path = require("path"), connect = require("connect"), utils = connect.utils, accept = require("./utils").accept, statusCodes = http.STATUS_CODES, send = connect["static"].send, mime = require("mime"), basename = path.basename, join = path.join; _$jscoverage['response.js'][28]++; var res = module.exports = {__proto__: http.ServerResponse.prototype}; _$jscoverage['response.js'][40]++; res.status = (function (code) { _$jscoverage['response.js'][41]++; this.statusCode = code; _$jscoverage['response.js'][42]++; return this; }); _$jscoverage['response.js'][58]++; res.cache = (function (type, options) { _$jscoverage['response.js'][59]++; var val = type; _$jscoverage['response.js'][60]++; options = options || {}; _$jscoverage['response.js'][61]++; if (options.maxAge) { _$jscoverage['response.js'][61]++; val += ", max-age=" + (options.maxAge / 1000); } _$jscoverage['response.js'][62]++; return this.set("Cache-Control", val); }); _$jscoverage['response.js'][82]++; res.send = (function (body) { _$jscoverage['response.js'][83]++; var req = this.req, head = "HEAD" == req.method; _$jscoverage['response.js'][87]++; if (2 == arguments.length) { _$jscoverage['response.js'][88]++; this.statusCode = body; _$jscoverage['response.js'][89]++; body = arguments[1]; } _$jscoverage['response.js'][92]++; switch (typeof body) { case "number": _$jscoverage['response.js'][95]++; this.get("Content-Type") || this.contentType(".txt"); _$jscoverage['response.js'][96]++; this.statusCode = body; _$jscoverage['response.js'][97]++; body = http.STATUS_CODES[body]; _$jscoverage['response.js'][98]++; break; case "string": _$jscoverage['response.js'][101]++; if (! this.get("Content-Type")) { _$jscoverage['response.js'][102]++; this.charset = this.charset || "utf-8"; _$jscoverage['response.js'][103]++; this.contentType(".html"); } _$jscoverage['response.js'][105]++; break; case "boolean": case "object": _$jscoverage['response.js'][108]++; if (null == body) { _$jscoverage['response.js'][109]++; body = ""; } else { _$jscoverage['response.js'][110]++; if (Buffer.isBuffer(body)) { _$jscoverage['response.js'][111]++; this.get("Content-Type") || this.contentType(".bin"); } else { _$jscoverage['response.js'][113]++; return this.json(body); } } _$jscoverage['response.js'][115]++; break; } _$jscoverage['response.js'][119]++; if (undefined !== body && ! this.get("Content-Length")) { _$jscoverage['response.js'][120]++; this.set("Content-Length", Buffer.isBuffer(body)? body.length: Buffer.byteLength(body)); } _$jscoverage['response.js'][126]++; if (204 == this.statusCode || 304 == this.statusCode) { _$jscoverage['response.js'][127]++; this.removeHeader("Content-Type"); _$jscoverage['response.js'][128]++; this.removeHeader("Content-Length"); _$jscoverage['response.js'][129]++; body = ""; } _$jscoverage['response.js'][133]++; this.end(head? null: body); _$jscoverage['response.js'][134]++; return this; }); _$jscoverage['response.js'][153]++; res.json = (function (obj) { _$jscoverage['response.js'][155]++; if (2 == arguments.length) { _$jscoverage['response.js'][156]++; this.statusCode = obj; _$jscoverage['response.js'][157]++; obj = arguments[1]; } _$jscoverage['response.js'][160]++; var settings = this.app.settings, jsonp = settings["jsonp callback"], replacer = settings["json replacer"], spaces = settings["json spaces"], body = JSON.stringify(obj, replacer, spaces), callback = this.req.query.callback; _$jscoverage['response.js'][167]++; this.charset = this.charset || "utf-8"; _$jscoverage['response.js'][168]++; this.set("Content-Type", "application/json"); _$jscoverage['response.js'][170]++; if (callback && jsonp) { _$jscoverage['response.js'][171]++; this.set("Content-Type", "text/javascript"); _$jscoverage['response.js'][172]++; body = callback.replace(/[^\w$.]/g, "") + "(" + body + ");"; } _$jscoverage['response.js'][175]++; return this.send(body); }); _$jscoverage['response.js'][198]++; res.sendfile = (function (path, options, fn) { _$jscoverage['response.js'][199]++; var self = this, req = self.req, next = this.req.next, options = options || {}; _$jscoverage['response.js'][205]++; if ("function" == typeof options) { _$jscoverage['response.js'][206]++; fn = options; _$jscoverage['response.js'][207]++; options = {}; } _$jscoverage['response.js'][211]++; options.callback = (function (err) { _$jscoverage['response.js'][212]++; if (err) { _$jscoverage['response.js'][214]++; if ("ENOENT" == err.code) { _$jscoverage['response.js'][214]++; err = 404; } _$jscoverage['response.js'][219]++; if ("number" == typeof err) { _$jscoverage['response.js'][219]++; err = utils.error(err); } _$jscoverage['response.js'][222]++; if (! self.headerSent) { _$jscoverage['response.js'][222]++; self.removeHeader("Content-Disposition"); } _$jscoverage['response.js'][225]++; if (fn) { _$jscoverage['response.js'][225]++; return fn(err); } _$jscoverage['response.js'][228]++; if (self.headerSent) { _$jscoverage['response.js'][228]++; return; } _$jscoverage['response.js'][230]++; return req.next(err); } _$jscoverage['response.js'][233]++; fn && fn(); }); _$jscoverage['response.js'][237]++; options.path = encodeURIComponent(path); _$jscoverage['response.js'][238]++; send(this.req, this, next, options); }); _$jscoverage['response.js'][255]++; res.download = (function (path, filename, fn) { _$jscoverage['response.js'][257]++; if ("function" == typeof filename) { _$jscoverage['response.js'][258]++; fn = filename; _$jscoverage['response.js'][259]++; filename = null; } _$jscoverage['response.js'][262]++; return this.attachment(filename || path).sendfile(path, fn); }); _$jscoverage['response.js'][285]++; res.contentType = res.type = (function (type) { _$jscoverage['response.js'][287]++; return this.set("Content-Type", mime.lookup(type)); }); _$jscoverage['response.js'][341]++; res.format = (function (obj) { _$jscoverage['response.js'][342]++; var keys = Object.keys(obj), types = [], req = this.req, next = req.next, accepted = req.accepted, acceptedlen = accepted.length, type, key; _$jscoverage['response.js'][352]++; if (acceptedlen) { _$jscoverage['response.js'][353]++; for (var i = 0; i < keys.length; ++i) { _$jscoverage['response.js'][354]++; types.push(~ keys[i].indexOf("/")? keys[i]: mime.lookup(keys[i])); } } _$jscoverage['response.js'][361]++; out: for (var i = 0; i < acceptedlen; ++i) { _$jscoverage['response.js'][363]++; for (var j = 0, jlen = types.length; j < jlen; ++j) { _$jscoverage['response.js'][364]++; if (accept(types[j].split("/"), accepted[i])) { _$jscoverage['response.js'][365]++; key = keys[j]; _$jscoverage['response.js'][366]++; type = types[j]; _$jscoverage['response.js'][367]++; break out; } } } _$jscoverage['response.js'][373]++; if (! acceptedlen) { _$jscoverage['response.js'][374]++; key = keys[0]; _$jscoverage['response.js'][375]++; type = types[0]; } _$jscoverage['response.js'][378]++; if (key) { _$jscoverage['response.js'][379]++; this.set("Content-Type", type); _$jscoverage['response.js'][380]++; obj[key](req, this, next); } else { _$jscoverage['response.js'][382]++; var err = new Error("Not Acceptable"); _$jscoverage['response.js'][383]++; err.status = 406; _$jscoverage['response.js'][384]++; err.types = types; _$jscoverage['response.js'][385]++; next(err); } _$jscoverage['response.js'][388]++; return this; }); _$jscoverage['response.js'][399]++; res.attachment = (function (filename) { _$jscoverage['response.js'][400]++; if (filename) { _$jscoverage['response.js'][400]++; this.type(filename); } _$jscoverage['response.js'][401]++; this.set("Content-Disposition", filename? "attachment; filename=\"" + basename(filename) + "\"": "attachment"); _$jscoverage['response.js'][404]++; return this; }); _$jscoverage['response.js'][422]++; res.set = (function (field, val) { _$jscoverage['response.js'][423]++; if (2 == arguments.length) { _$jscoverage['response.js'][424]++; this.setHeader(field, val); } else { _$jscoverage['response.js'][426]++; for (var key in field) { _$jscoverage['response.js'][427]++; this.setHeader(key, field[key]); } } _$jscoverage['response.js'][430]++; return this; }); _$jscoverage['response.js'][441]++; res.get = (function (field) { _$jscoverage['response.js'][442]++; return this.getHeader(field); }); _$jscoverage['response.js'][454]++; res.clearCookie = (function (name, options) { _$jscoverage['response.js'][455]++; var opts = {expires: new Date(1), path: "/"}; _$jscoverage['response.js'][456]++; return this.cookie(name, "", options? utils.merge(opts, options): opts); }); _$jscoverage['response.js'][471]++; res.signedCookie = (function (name, val, options) { _$jscoverage['response.js'][472]++; var secret = this.req.secret; _$jscoverage['response.js'][473]++; if (! secret) { _$jscoverage['response.js'][473]++; throw new Error("connect.cookieParser(\"secret\") required for signed cookies"); } _$jscoverage['response.js'][474]++; if ("object" == typeof val) { _$jscoverage['response.js'][474]++; val = "j:" + JSON.stringify(val); } _$jscoverage['response.js'][475]++; val = utils.sign(val, secret); _$jscoverage['response.js'][476]++; return this.cookie(name, val, options); }); _$jscoverage['response.js'][501]++; res.cookie = (function (name, val, options) { _$jscoverage['response.js'][502]++; options = options || {}; _$jscoverage['response.js'][503]++; if ("object" == typeof val) { _$jscoverage['response.js'][503]++; val = "j:" + JSON.stringify(val); } _$jscoverage['response.js'][504]++; if ("maxAge" in options) { _$jscoverage['response.js'][504]++; options.expires = new Date(Date.now() + options.maxAge); } _$jscoverage['response.js'][505]++; if (null == options.path) { _$jscoverage['response.js'][505]++; options.path = "/"; } _$jscoverage['response.js'][506]++; var cookie = utils.serializeCookie(name, val, options); _$jscoverage['response.js'][507]++; this.set("Set-Cookie", cookie); _$jscoverage['response.js'][508]++; return this; }); _$jscoverage['response.js'][543]++; res.redirect = (function (url) { _$jscoverage['response.js'][544]++; var app = this.app, req = this.req, head = "HEAD" == req.method, status = 302, body; _$jscoverage['response.js'][551]++; if (2 == arguments.length) { _$jscoverage['response.js'][552]++; status = url; _$jscoverage['response.js'][553]++; url = arguments[1]; } _$jscoverage['response.js'][557]++; var map = {back: req.get("Referrer") || "/"}; _$jscoverage['response.js'][560]++; url = map[url] || url; _$jscoverage['response.js'][563]++; if (! ~ url.indexOf("://")) { _$jscoverage['response.js'][564]++; var path = app.path(); _$jscoverage['response.js'][567]++; if (0 == url.indexOf("./") || 0 == url.indexOf("..")) { _$jscoverage['response.js'][568]++; url = req.path + "/" + url; } else { _$jscoverage['response.js'][570]++; if ("/" != url[0]) { _$jscoverage['response.js'][571]++; url = path + "/" + url; } } _$jscoverage['response.js'][575]++; var host = req.get("Host"); _$jscoverage['response.js'][576]++; url = req.protocol + "://" + host + url; } _$jscoverage['response.js'][580]++; this.format({"text/plain": (function () { _$jscoverage['response.js'][582]++; body = statusCodes[status] + ". Redirecting to " + url; }), "text/html": (function () { _$jscoverage['response.js'][586]++; body = "

" + statusCodes[status] + ". Redirecting to " + url + "

"; })}); _$jscoverage['response.js'][591]++; this.statusCode = status; _$jscoverage['response.js'][592]++; this.set("Location", url); _$jscoverage['response.js'][593]++; this.end(head? null: body); }); _$jscoverage['response.js'][617]++; res.render = (function (view, options, fn) { _$jscoverage['response.js'][618]++; var self = this, options = options || {}, req = this.req, app = req.app; _$jscoverage['response.js'][624]++; if ("function" == typeof options) { _$jscoverage['response.js'][625]++; fn = options, options = {}; } _$jscoverage['response.js'][628]++; function render() { _$jscoverage['response.js'][630]++; options.locals = self.locals; _$jscoverage['response.js'][633]++; fn = fn || (function (err, str) { _$jscoverage['response.js'][634]++; if (err) { _$jscoverage['response.js'][634]++; return req.next(err); } _$jscoverage['response.js'][635]++; self.send(str); }); _$jscoverage['response.js'][639]++; app.render(view, options, fn); } _$jscoverage['response.js'][643]++; var callbacks = app.viewCallbacks, pending = callbacks.length, len = pending, done; _$jscoverage['response.js'][648]++; if (len) { _$jscoverage['response.js'][649]++; for (var i = 0; i < len; ++i) { _$jscoverage['response.js'][650]++; callbacks[i](req, self, (function (err) { _$jscoverage['response.js'][651]++; if (done) { _$jscoverage['response.js'][651]++; return; } _$jscoverage['response.js'][653]++; if (err) { _$jscoverage['response.js'][654]++; req.next(err); _$jscoverage['response.js'][655]++; done = true; _$jscoverage['response.js'][656]++; return; } _$jscoverage['response.js'][659]++; --pending || render(); })); } } else { _$jscoverage['response.js'][663]++; render(); } }); _$jscoverage['response.js'].source = ["","/*!"," * Express - response"," * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>"," * MIT Licensed"," */","","/**"," * Module dependencies."," */","","var fs = require('fs')"," , http = require('http')"," , path = require('path')"," , connect = require('connect')"," , utils = connect.utils"," , accept = require('./utils').accept"," , statusCodes = http.STATUS_CODES"," , send = connect.static.send"," , mime = require('mime')"," , basename = path.basename"," , join = path.join;","","/**"," * Response prototype."," */","","var res = module.exports = {"," __proto__: http.ServerResponse.prototype","};","","/**"," * Set status `code`."," *"," * @param {Number} code"," * @return {ServerResponse}"," * @api public"," */","","res.status = function(code){"," this.statusCode = code;"," return this;","};","","/**"," * Set Cache-Control to the given `type` and `options`."," *"," * Options:"," *"," * - `maxAge` in milliseconds"," *"," * @param {String} type"," * @param {Object} options"," * @return {ServerResponse}"," * @api public"," */","","res.cache = function(type, options){"," var val = type;"," options = options || {};"," if (options.maxAge) val += ', max-age=' + (options.maxAge / 1000); "," return this.set('Cache-Control', val);","};","","/**"," * Send a response."," *"," * Examples:"," *"," * res.send(new Buffer('wahoo'));"," * res.send({ some: 'json' });"," * res.send('<p>some html</p>');"," * res.send(404, 'Sorry, cant find that');"," * res.send(404);"," *"," * @param {Mixed} body or status"," * @param {Mixed} body"," * @return {ServerResponse}"," * @api public"," */","","res.send = function(body){"," var req = this.req"," , head = 'HEAD' == req.method;",""," // allow status / body"," if (2 == arguments.length) {"," this.statusCode = body;"," body = arguments[1];"," }",""," switch (typeof body) {"," // response status"," case 'number':"," this.get('Content-Type') || this.contentType('.txt');"," this.statusCode = body;"," body = http.STATUS_CODES[body];"," break;"," // string defaulting to html"," case 'string':"," if (!this.get('Content-Type')) {"," this.charset = this.charset || 'utf-8';"," this.contentType('.html');"," }"," break;"," case 'boolean':"," case 'object':"," if (null == body) {"," body = '';"," } else if (Buffer.isBuffer(body)) {"," this.get('Content-Type') || this.contentType('.bin');"," } else {"," return this.json(body);"," }"," break;"," }",""," // populate Content-Length"," if (undefined !== body && !this.get('Content-Length')) {"," this.set('Content-Length', Buffer.isBuffer(body)"," ? body.length"," : Buffer.byteLength(body));"," }",""," // strip irrelevant headers"," if (204 == this.statusCode || 304 == this.statusCode) {"," this.removeHeader('Content-Type');"," this.removeHeader('Content-Length');"," body = '';"," }",""," // respond"," this.end(head ? null : body);"," return this;","};","","/**"," * Send JSON response."," *"," * Examples:"," *"," * res.json(null);"," * res.json({ user: 'tj' });"," * res.json(500, 'oh noes!');"," * res.json(404, 'I dont have that');"," *"," * @param {Mixed} obj or status"," * @param {Mixed} obj"," * @return {ServerResponse}"," * @api public"," */","","res.json = function(obj){"," // allow status / body"," if (2 == arguments.length) {"," this.statusCode = obj;"," obj = arguments[1];"," }",""," var settings = this.app.settings"," , jsonp = settings['jsonp callback']"," , replacer = settings['json replacer']"," , spaces = settings['json spaces']"," , body = JSON.stringify(obj, replacer, spaces)"," , callback = this.req.query.callback;",""," this.charset = this.charset || 'utf-8';"," this.set('Content-Type', 'application/json');",""," if (callback && jsonp) {"," this.set('Content-Type', 'text/javascript');"," body = callback.replace(/[^\\w$.]/g, '') + '(' + body + ');';"," }",""," return this.send(body);","};","","/**"," * Transfer the file at the given `path`."," * "," * Automatically sets the _Content-Type_ response header field."," * The callback `fn(err)` is invoked when the transfer is complete"," * or when an error occurs. Be sure to check `res.sentHeader`"," * if you wish to attempt responding, as the header and some data"," * may have already been transferred."," *"," * Options:"," *"," * - `maxAge` defaulting to 0"," * - `root` root directory for relative filenames"," *"," * @param {String} path"," * @param {Object|Function} options or fn"," * @param {Function} fn"," * @api public"," */","","res.sendfile = function(path, options, fn){"," var self = this"," , req = self.req"," , next = this.req.next"," , options = options || {};",""," // support function as second arg"," if ('function' == typeof options) {"," fn = options;"," options = {};"," }",""," // callback"," options.callback = function(err){"," if (err) {"," // cast ENOENT"," if ('ENOENT' == err.code) err = 404;",""," // coerce numeric error to an Error"," // TODO: remove"," // TODO: remove docs for headerSent?"," if ('number' == typeof err) err = utils.error(err);",""," // ditch content-disposition to prevent funky responses"," if (!self.headerSent) self.removeHeader('Content-Disposition');",""," // woot! callback available"," if (fn) return fn(err);",""," // lost in limbo if there's no callback"," if (self.headerSent) return;",""," return req.next(err);"," }",""," fn && fn();"," };",""," // transfer"," options.path = encodeURIComponent(path);"," send(this.req, this, next, options);","};","","/**"," * Transfer the file at the given `path` as an attachment."," *"," * Optionally providing an alternate attachment `filename`,"," * and optional callback `fn(err)`. The callback is invoked"," * when the data transfer is complete, or when an error has"," * ocurred. Be sure to check `res.headerSent` if you plan to respond."," *"," * @param {String} path"," * @param {String|Function} filename or fn"," * @param {Function} fn"," * @api public"," */","","res.download = function(path, filename, fn){"," // support function as second arg"," if ('function' == typeof filename) {"," fn = filename;"," filename = null;"," }",""," return this.attachment(filename || path).sendfile(path, fn);","};","","/**"," * Set _Content-Type_ response header passed through `mime.lookup()`."," *"," * Examples:"," *"," * var filename = 'path/to/image.png';"," * res.contentType(filename);"," * // res.headers['Content-Type'] is now \"image/png\""," *"," * res.contentType('.html');"," * res.contentType('html');"," * res.contentType('json');"," * res.contentType('png');"," * res.type('png');"," *"," * @param {String} type"," * @return {ServerResponse} for chaining"," * @api public"," */","","res.contentType =","res.type = function(type){"," return this.set('Content-Type', mime.lookup(type));","};","","/**"," * Respond to the Acceptable formats using an `obj`"," * of mime-type callbacks."," *"," * This method uses `req.accepted`, an array of"," * acceptable types ordered by their quality values."," * When \"Accept\" is not present the _first_ callback"," * is invoked, otherwise the first match is used. When"," * no match is performed the server responds with"," * 406 \"Not Acceptable\"."," *"," * Content-Type is set for you, however if you choose"," * you may alter this within the callback using `res.type()`"," * or `res.set('Content-Type', ...)`."," *"," * res.format({"," * 'text/plain': function(){"," * res.send('hey');"," * },"," * "," * 'text/html': function(){"," * res.send('<p>hey</p>');"," * },"," * "," * 'appliation/json': function(){"," * res.send({ message: 'hey' });"," * }"," * });"," *"," * In addition to canonicalized MIME types you may"," * also use extnames mapped to these types:"," *"," * res.format({"," * text: function(){"," * res.send('hey');"," * },"," * "," * html: function(){"," * res.send('<p>hey</p>');"," * },"," * "," * json: function(){"," * res.send({ message: 'hey' });"," * }"," * });"," *"," * @param {Object} obj"," * @return {ServerResponse} for chaining"," * @api public"," */","","res.format = function(obj){"," var keys = Object.keys(obj)"," , types = []"," , req = this.req"," , next = req.next"," , accepted = req.accepted"," , acceptedlen = accepted.length"," , type"," , key;",""," // normalize extnames -> mime"," if (acceptedlen) {"," for (var i = 0; i < keys.length; ++i) {"," types.push(~keys[i].indexOf('/')"," ? keys[i]"," : mime.lookup(keys[i]));"," }"," }",""," // determine most acceptable format"," out:"," for (var i = 0; i < acceptedlen; ++i) {"," for (var j = 0, jlen = types.length; j < jlen; ++j) {"," if (accept(types[j].split('/'), accepted[i])) {"," key = keys[j];"," type = types[j];"," break out;"," }"," }"," }",""," // default to the first"," if (!acceptedlen) {"," key = keys[0];"," type = types[0];"," }",""," if (key) {"," this.set('Content-Type', type);"," obj[key](req, this, next);"," } else {"," var err = new Error('Not Acceptable');"," err.status = 406;"," err.types = types;"," next(err);"," }",""," return this;","};","","/**"," * Set _Content-Disposition_ header to _attachment_ with optional `filename`."," *"," * @param {String} filename"," * @return {ServerResponse}"," * @api public"," */","","res.attachment = function(filename){"," if (filename) this.type(filename);"," this.set('Content-Disposition', filename"," ? 'attachment; filename=\"' + basename(filename) + '\"'"," : 'attachment');"," return this;","};","","/**"," * Set header `field` to `val`, or pass"," * an object of of header fields."," *"," * Examples:"," *"," * res.set('Accept', 'application/json');"," * res.set({ Accept: 'text/plain', 'X-API-Key': 'tobi' });"," *"," * @param {String|Object} field"," * @param {String} val"," * @return {ServerResponse} for chaining"," * @api public"," */","","res.set = function(field, val){"," if (2 == arguments.length) {"," this.setHeader(field, val);"," } else {"," for (var key in field) {"," this.setHeader(key, field[key]);"," }"," }"," return this;","};","","/**"," * Get value for header `field`."," *"," * @param {String} field"," * @return {String}"," * @api public"," */","","res.get = function(field){"," return this.getHeader(field);","};","","/**"," * Clear cookie `name`."," *"," * @param {String} name"," * @param {Object} options"," * @param {ServerResponse} for chaining"," * @api public"," */","","res.clearCookie = function(name, options){"," var opts = { expires: new Date(1), path: '/' };"," return this.cookie(name, '', options"," ? utils.merge(opts, options)"," : opts);","};","","/**"," * Set a signed cookie with the given `name` and `val`."," * See `res.cookie()` for details."," *"," * @param {String} name"," * @param {String|Object} val"," * @param {Object} options"," * @api public"," */","","res.signedCookie = function(name, val, options){"," var secret = this.req.secret;"," if (!secret) throw new Error('connect.cookieParser(\"secret\") required for signed cookies');"," if ('object' == typeof val) val = 'j:' + JSON.stringify(val);"," val = utils.sign(val, secret);"," return this.cookie(name, val, options);","};","","/**"," * Set cookie `name` to `val`, with the given `options`."," *"," * Options:"," *"," * - `maxAge` max-age in milliseconds, converted to `expires`"," * - `path` defaults to \"/\""," *"," * Examples:"," *"," * // \"Remember Me\" for 15 minutes"," * res.cookie('rememberme', '1', { expires: new Date(Date.now() + 900000), httpOnly: true });"," *"," * // save as above"," * res.cookie('rememberme', '1', { maxAge: 900000, httpOnly: true })"," *"," * @param {String} name"," * @param {String|Object} val"," * @param {Options} options"," * @api public"," */","","res.cookie = function(name, val, options){"," options = options || {};"," if ('object' == typeof val) val = 'j:' + JSON.stringify(val);"," if ('maxAge' in options) options.expires = new Date(Date.now() + options.maxAge);"," if (null == options.path) options.path = '/';"," var cookie = utils.serializeCookie(name, val, options);"," this.set('Set-Cookie', cookie);"," return this;","};","","/**"," * Redirect to the given `url` with optional response `status`"," * defaulting to 302."," *"," * The given `url` can also be the name of a mapped url, for"," * example by default express supports \"back\" which redirects"," * to the _Referrer_ or _Referer_ headers or \"/\"."," *"," * Examples:"," *"," * res.redirect('/foo/bar');"," * res.redirect('http://example.com');"," * res.redirect(301, 'http://example.com');"," *"," * Mounting:"," *"," * When an application is mounted, and `res.redirect()`"," * is given a path that does _not_ lead with \"/\". For "," * example suppose a \"blog\" app is mounted at \"/blog\","," * the following redirect would result in \"/blog/login\":"," *"," * res.redirect('login');"," *"," * While the leading slash would result in a redirect to \"/login\":"," *"," * res.redirect('/login');"," *"," * @param {String} url"," * @param {Number} code"," * @api public"," */","","res.redirect = function(url){"," var app = this.app"," , req = this.req"," , head = 'HEAD' == req.method"," , status = 302"," , body;",""," // allow status / url"," if (2 == arguments.length) {"," status = url;"," url = arguments[1];"," }",""," // setup redirect map"," var map = { back: req.get('Referrer') || '/' };",""," // perform redirect"," url = map[url] || url;",""," // relative"," if (!~url.indexOf('://')) {"," var path = app.path();",""," // relative to path"," if (0 == url.indexOf('./') || 0 == url.indexOf('..')) {"," url = req.path + '/' + url;"," // relative to mount-point"," } else if ('/' != url[0]) {"," url = path + '/' + url;"," }",""," // Absolute"," var host = req.get('Host');"," url = req.protocol + '://' + host + url;"," }",""," // Support text/{plain,html} by default"," this.format({"," 'text/plain': function(){"," body = statusCodes[status] + '. Redirecting to ' + url;"," },",""," 'text/html': function(){"," body = '<p>' + statusCodes[status] + '. Redirecting to <a href=\"' + url + '\">' + url + '</a></p>';"," }"," })",""," // Respond"," this.statusCode = status;"," this.set('Location', url);"," this.end(head ? null : body);","};","","/**"," * Render `view` with the given `options` and optional callback `fn`."," * When a callback function is given a response will _not_ be made"," * automatically, otherwise a response of _200_ and _text/html_ is given."," *"," * Options:"," * "," * - `status` Response status code (`res.statusCode`)"," * - `charset` Set the charset (`res.charset`)"," *"," * Reserved locals:"," *"," * - `cache` boolean hinting to the engine it should cache"," * - `filename` filename of the view being rendered"," *"," * @param {String} view"," * @param {Object|Function} options or callback function"," * @param {Function} fn"," * @api public"," */","","res.render = function(view, options, fn){"," var self = this"," , options = options || {}"," , req = this.req"," , app = req.app;",""," // support callback function as second arg"," if ('function' == typeof options) {"," fn = options, options = {};"," }",""," function render() {"," // merge res.locals"," options.locals = self.locals;",""," // default callback to respond"," fn = fn || function(err, str){"," if (err) return req.next(err);"," self.send(str);"," };",""," // render"," app.render(view, options, fn);"," }",""," // invoke view callbacks"," var callbacks = app.viewCallbacks"," , pending = callbacks.length"," , len = pending"," , done;",""," if (len) {"," for (var i = 0; i < len; ++i) {"," callbacks[i](req, self, function(err){"," if (done) return;",""," if (err) {"," req.next(err);"," done = true;"," return;"," }",""," --pending || render();"," });"," }"," } else {"," render();"," }","};"]; package/lib-cov/router/000755 000765 000024 0000000000 11736457244013417 5ustar00000000 000000 package/lib-cov/router/collection.js000644 000765 000024 0000005026 11722507472016105 0ustar00000000 000000 /* automatically generated by JSCoverage - do not edit */ if (typeof _$jscoverage === 'undefined') _$jscoverage = {}; if (! _$jscoverage['router/collection.js']) { _$jscoverage['router/collection.js'] = []; _$jscoverage['router/collection.js'][12] = 0; _$jscoverage['router/collection.js'][22] = 0; _$jscoverage['router/collection.js'][23] = 0; _$jscoverage['router/collection.js'][30] = 0; _$jscoverage['router/collection.js'][39] = 0; _$jscoverage['router/collection.js'][40] = 0; _$jscoverage['router/collection.js'][44] = 0; _$jscoverage['router/collection.js'][45] = 0; _$jscoverage['router/collection.js'][46] = 0; _$jscoverage['router/collection.js'][50] = 0; } _$jscoverage['router/collection.js'][12]++; module.exports = Collection; _$jscoverage['router/collection.js'][22]++; function Collection(router) { _$jscoverage['router/collection.js'][23]++; Object.defineProperty(this, "router", {value: router}); } _$jscoverage['router/collection.js'][30]++; Collection.prototype.__proto__ = Array.prototype; _$jscoverage['router/collection.js'][39]++; Collection.prototype.remove = (function () { _$jscoverage['router/collection.js'][40]++; var router = this.router, len = this.length, ret = new Collection(this.router); _$jscoverage['router/collection.js'][44]++; for (var i = 0; i < len; ++i) { _$jscoverage['router/collection.js'][45]++; if (router.remove(this[i])) { _$jscoverage['router/collection.js'][46]++; ret.push(this[i]); } } _$jscoverage['router/collection.js'][50]++; return ret; }); _$jscoverage['router/collection.js'].source = ["","/*!"," * Express - router - Collection"," * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>"," * MIT Licensed"," */","","/**"," * Expose `Collection`."," */","","module.exports = Collection;","","/**"," * Initialize a new route `Collection`"," * with the given `router`."," * "," * @param {Router} router"," * @api private"," */","","function Collection(router) {"," Object.defineProperty(this, 'router', { value: router });","}","","/**"," * Inherit from `Array.prototype`."," */","","Collection.prototype.__proto__ = Array.prototype;","","/**"," * Remove the routes in this collection."," *"," * @return {Collection} of routes removed"," * @api public"," */","","Collection.prototype.remove = function(){"," var router = this.router"," , len = this.length"," , ret = new Collection(this.router);",""," for (var i = 0; i < len; ++i) {"," if (router.remove(this[i])) {"," ret.push(this[i]);"," }"," }",""," return ret;","};",""]; package/lib-cov/router/index.js000644 000765 000024 0000070027 11722507472015064 0ustar00000000 000000 /* automatically generated by JSCoverage - do not edit */ if (typeof _$jscoverage === 'undefined') _$jscoverage = {}; if (! _$jscoverage['router/index.js']) { _$jscoverage['router/index.js'] = []; _$jscoverage['router/index.js'][11] = 0; _$jscoverage['router/index.js'][21] = 0; _$jscoverage['router/index.js'][27] = 0; _$jscoverage['router/index.js'][36] = 0; _$jscoverage['router/index.js'][37] = 0; _$jscoverage['router/index.js'][38] = 0; _$jscoverage['router/index.js'][39] = 0; _$jscoverage['router/index.js'][40] = 0; _$jscoverage['router/index.js'][41] = 0; _$jscoverage['router/index.js'][42] = 0; _$jscoverage['router/index.js'][43] = 0; _$jscoverage['router/index.js'][44] = 0; _$jscoverage['router/index.js'][46] = 0; _$jscoverage['router/index.js'][47] = 0; _$jscoverage['router/index.js'][60] = 0; _$jscoverage['router/index.js'][62] = 0; _$jscoverage['router/index.js'][63] = 0; _$jscoverage['router/index.js'][64] = 0; _$jscoverage['router/index.js'][68] = 0; _$jscoverage['router/index.js'][72] = 0; _$jscoverage['router/index.js'][73] = 0; _$jscoverage['router/index.js'][74] = 0; _$jscoverage['router/index.js'][80] = 0; _$jscoverage['router/index.js'][81] = 0; _$jscoverage['router/index.js'][84] = 0; _$jscoverage['router/index.js'][85] = 0; _$jscoverage['router/index.js'][95] = 0; _$jscoverage['router/index.js'][96] = 0; _$jscoverage['router/index.js'][97] = 0; _$jscoverage['router/index.js'][111] = 0; _$jscoverage['router/index.js'][112] = 0; _$jscoverage['router/index.js'][116] = 0; _$jscoverage['router/index.js'][117] = 0; _$jscoverage['router/index.js'][120] = 0; _$jscoverage['router/index.js'][121] = 0; _$jscoverage['router/index.js'][122] = 0; _$jscoverage['router/index.js'][123] = 0; _$jscoverage['router/index.js'][137] = 0; _$jscoverage['router/index.js'][138] = 0; _$jscoverage['router/index.js'][139] = 0; _$jscoverage['router/index.js'][171] = 0; _$jscoverage['router/index.js'][172] = 0; _$jscoverage['router/index.js'][178] = 0; _$jscoverage['router/index.js'][179] = 0; _$jscoverage['router/index.js'][180] = 0; _$jscoverage['router/index.js'][181] = 0; _$jscoverage['router/index.js'][182] = 0; _$jscoverage['router/index.js'][183] = 0; _$jscoverage['router/index.js'][184] = 0; _$jscoverage['router/index.js'][188] = 0; _$jscoverage['router/index.js'][200] = 0; _$jscoverage['router/index.js'][201] = 0; _$jscoverage['router/index.js'][204] = 0; _$jscoverage['router/index.js'][207] = 0; _$jscoverage['router/index.js'][208] = 0; _$jscoverage['router/index.js'][217] = 0; _$jscoverage['router/index.js'][218] = 0; _$jscoverage['router/index.js'][222] = 0; _$jscoverage['router/index.js'][225] = 0; _$jscoverage['router/index.js'][228] = 0; _$jscoverage['router/index.js'][229] = 0; _$jscoverage['router/index.js'][233] = 0; _$jscoverage['router/index.js'][234] = 0; _$jscoverage['router/index.js'][235] = 0; _$jscoverage['router/index.js'][238] = 0; _$jscoverage['router/index.js'][239] = 0; _$jscoverage['router/index.js'][240] = 0; _$jscoverage['router/index.js'][241] = 0; _$jscoverage['router/index.js'][242] = 0; _$jscoverage['router/index.js'][244] = 0; _$jscoverage['router/index.js'][245] = 0; _$jscoverage['router/index.js'][246] = 0; _$jscoverage['router/index.js'][247] = 0; _$jscoverage['router/index.js'][248] = 0; _$jscoverage['router/index.js'][249] = 0; _$jscoverage['router/index.js'][250] = 0; _$jscoverage['router/index.js'][251] = 0; _$jscoverage['router/index.js'][252] = 0; _$jscoverage['router/index.js'][253] = 0; _$jscoverage['router/index.js'][255] = 0; _$jscoverage['router/index.js'][256] = 0; _$jscoverage['router/index.js'][259] = 0; _$jscoverage['router/index.js'][261] = 0; _$jscoverage['router/index.js'][263] = 0; _$jscoverage['router/index.js'][266] = 0; _$jscoverage['router/index.js'][267] = 0; _$jscoverage['router/index.js'][268] = 0; _$jscoverage['router/index.js'][269] = 0; _$jscoverage['router/index.js'][273] = 0; _$jscoverage['router/index.js'][274] = 0; _$jscoverage['router/index.js'][275] = 0; _$jscoverage['router/index.js'][276] = 0; _$jscoverage['router/index.js'][277] = 0; _$jscoverage['router/index.js'][278] = 0; _$jscoverage['router/index.js'][279] = 0; _$jscoverage['router/index.js'][280] = 0; _$jscoverage['router/index.js'][281] = 0; _$jscoverage['router/index.js'][282] = 0; _$jscoverage['router/index.js'][284] = 0; _$jscoverage['router/index.js'][287] = 0; _$jscoverage['router/index.js'][301] = 0; _$jscoverage['router/index.js'][302] = 0; _$jscoverage['router/index.js'][304] = 0; _$jscoverage['router/index.js'][315] = 0; _$jscoverage['router/index.js'][316] = 0; _$jscoverage['router/index.js'][317] = 0; _$jscoverage['router/index.js'][318] = 0; _$jscoverage['router/index.js'][319] = 0; _$jscoverage['router/index.js'][320] = 0; _$jscoverage['router/index.js'][321] = 0; _$jscoverage['router/index.js'][324] = 0; _$jscoverage['router/index.js'][339] = 0; _$jscoverage['router/index.js'][340] = 0; _$jscoverage['router/index.js'][351] = 0; _$jscoverage['router/index.js'][353] = 0; _$jscoverage['router/index.js'][354] = 0; _$jscoverage['router/index.js'][358] = 0; _$jscoverage['router/index.js'][362] = 0; _$jscoverage['router/index.js'][365] = 0; _$jscoverage['router/index.js'][366] = 0; _$jscoverage['router/index.js'][367] = 0; _$jscoverage['router/index.js'][368] = 0; _$jscoverage['router/index.js'][369] = 0; _$jscoverage['router/index.js'][372] = 0; _$jscoverage['router/index.js'][373] = 0; _$jscoverage['router/index.js'][377] = 0; _$jscoverage['router/index.js'][378] = 0; _$jscoverage['router/index.js'][380] = 0; _$jscoverage['router/index.js'][385] = 0; _$jscoverage['router/index.js'][386] = 0; _$jscoverage['router/index.js'][402] = 0; _$jscoverage['router/index.js'][403] = 0; _$jscoverage['router/index.js'][408] = 0; _$jscoverage['router/index.js'][411] = 0; _$jscoverage['router/index.js'][412] = 0; _$jscoverage['router/index.js'][418] = 0; _$jscoverage['router/index.js'][419] = 0; _$jscoverage['router/index.js'][420] = 0; } _$jscoverage['router/index.js'][11]++; var Route = require("./route"), Collection = require("./collection"), utils = require("../utils"), debug = require("debug")("express:router"), parse = require("url").parse; _$jscoverage['router/index.js'][21]++; exports = module.exports = Router; _$jscoverage['router/index.js'][27]++; var methods = exports.methods = require("./methods"); _$jscoverage['router/index.js'][36]++; function Router(options) { _$jscoverage['router/index.js'][37]++; options = options || {}; _$jscoverage['router/index.js'][38]++; var self = this; _$jscoverage['router/index.js'][39]++; this.routes = new Collection(); _$jscoverage['router/index.js'][40]++; this.map = {}; _$jscoverage['router/index.js'][41]++; this.params = {}; _$jscoverage['router/index.js'][42]++; this._params = []; _$jscoverage['router/index.js'][43]++; this.caseSensitive = options.caseSensitive; _$jscoverage['router/index.js'][44]++; this.strict = options.strict; _$jscoverage['router/index.js'][46]++; this.middleware = (function router(req, res, next) { _$jscoverage['router/index.js'][47]++; self._dispatch(req, res, next); }); } _$jscoverage['router/index.js'][60]++; Router.prototype.param = (function (name, fn) { _$jscoverage['router/index.js'][62]++; if ("function" == typeof name) { _$jscoverage['router/index.js'][63]++; this._params.push(name); _$jscoverage['router/index.js'][64]++; return; } _$jscoverage['router/index.js'][68]++; var params = this._params, len = params.length, ret; _$jscoverage['router/index.js'][72]++; for (var i = 0; i < len; ++i) { _$jscoverage['router/index.js'][73]++; if (ret = params[i](name, fn)) { _$jscoverage['router/index.js'][74]++; fn = ret; } } _$jscoverage['router/index.js'][80]++; if ("function" != typeof fn) { _$jscoverage['router/index.js'][81]++; throw new Error("invalid param() call for " + name + ", got " + fn); } _$jscoverage['router/index.js'][84]++; (this.params[name] = this.params[name] || []).push(fn); _$jscoverage['router/index.js'][85]++; return this; }); _$jscoverage['router/index.js'][95]++; Router.prototype.all = (function () { _$jscoverage['router/index.js'][96]++; return this.find((function () { _$jscoverage['router/index.js'][97]++; return true; })); }); _$jscoverage['router/index.js'][111]++; Router.prototype.remove = (function (route) { _$jscoverage['router/index.js'][112]++; var routes = this.map[route.method], len = routes.length; _$jscoverage['router/index.js'][116]++; var i = this.routes.indexOf(route); _$jscoverage['router/index.js'][117]++; this.routes.splice(i, 1); _$jscoverage['router/index.js'][120]++; for (var i = 0; i < len; ++i) { _$jscoverage['router/index.js'][121]++; if (route == routes[i]) { _$jscoverage['router/index.js'][122]++; routes.splice(i, 1); _$jscoverage['router/index.js'][123]++; return true; } } }); _$jscoverage['router/index.js'][137]++; Router.prototype.lookup = (function (method, path) { _$jscoverage['router/index.js'][138]++; return this.find((function (route) { _$jscoverage['router/index.js'][139]++; return path == route.path && (route.method == method || method == "all"); })); }); _$jscoverage['router/index.js'][171]++; Router.prototype.find = (function (fn) { _$jscoverage['router/index.js'][172]++; var len = methods.length, ret = new Collection(this), method, routes, route; _$jscoverage['router/index.js'][178]++; for (var i = 0; i < len; ++i) { _$jscoverage['router/index.js'][179]++; method = methods[i]; _$jscoverage['router/index.js'][180]++; routes = this.map[method]; _$jscoverage['router/index.js'][181]++; if (! routes) { _$jscoverage['router/index.js'][181]++; continue; } _$jscoverage['router/index.js'][182]++; for (var j = 0, jlen = routes.length; j < jlen; ++j) { _$jscoverage['router/index.js'][183]++; route = routes[j]; _$jscoverage['router/index.js'][184]++; if (fn(route)) { _$jscoverage['router/index.js'][184]++; ret.push(route); } } } _$jscoverage['router/index.js'][188]++; return ret; }); _$jscoverage['router/index.js'][200]++; Router.prototype._dispatch = (function (req, res, next) { _$jscoverage['router/index.js'][201]++; var params = this.params, self = this; _$jscoverage['router/index.js'][204]++; debug("dispatching %s %s", req.method, req.url); _$jscoverage['router/index.js'][207]++; (function pass(i, err) { _$jscoverage['router/index.js'][208]++; var paramCallbacks, paramIndex = 0, paramVal, route, keys, key, ret; _$jscoverage['router/index.js'][217]++; function nextRoute(err) { _$jscoverage['router/index.js'][218]++; pass(req._route_index + 1, err); } _$jscoverage['router/index.js'][222]++; req.route = route = self.match(req, i); _$jscoverage['router/index.js'][225]++; if (! route && "OPTIONS" == req.method) { _$jscoverage['router/index.js'][225]++; return self._options(req, res); } _$jscoverage['router/index.js'][228]++; if (! route) { _$jscoverage['router/index.js'][228]++; return next(err); } _$jscoverage['router/index.js'][229]++; debug("matched %s %s", route.method, route.path); _$jscoverage['router/index.js'][233]++; req.params = route.params; _$jscoverage['router/index.js'][234]++; keys = route.keys; _$jscoverage['router/index.js'][235]++; i = 0; _$jscoverage['router/index.js'][238]++; function param(err) { _$jscoverage['router/index.js'][239]++; paramIndex = 0; _$jscoverage['router/index.js'][240]++; key = keys[i++]; _$jscoverage['router/index.js'][241]++; paramVal = key && req.params[key.name]; _$jscoverage['router/index.js'][242]++; paramCallbacks = key && params[key.name]; _$jscoverage['router/index.js'][244]++; try { _$jscoverage['router/index.js'][245]++; if ("route" == err) { _$jscoverage['router/index.js'][246]++; nextRoute(); } else { _$jscoverage['router/index.js'][247]++; if (err) { _$jscoverage['router/index.js'][248]++; i = 0; _$jscoverage['router/index.js'][249]++; callbacks(err); } else { _$jscoverage['router/index.js'][250]++; if (paramCallbacks && undefined !== paramVal) { _$jscoverage['router/index.js'][251]++; paramCallback(); } else { _$jscoverage['router/index.js'][252]++; if (key) { _$jscoverage['router/index.js'][253]++; param(); } else { _$jscoverage['router/index.js'][255]++; i = 0; _$jscoverage['router/index.js'][256]++; callbacks(); } } } } } catch (err) { _$jscoverage['router/index.js'][259]++; param(err); } } _$jscoverage['router/index.js'][261]++; ; _$jscoverage['router/index.js'][263]++; param(err); _$jscoverage['router/index.js'][266]++; function paramCallback(err) { _$jscoverage['router/index.js'][267]++; var fn = paramCallbacks[paramIndex++]; _$jscoverage['router/index.js'][268]++; if (err || ! fn) { _$jscoverage['router/index.js'][268]++; return param(err); } _$jscoverage['router/index.js'][269]++; fn(req, res, paramCallback, paramVal, key.name); } _$jscoverage['router/index.js'][273]++; function callbacks(err) { _$jscoverage['router/index.js'][274]++; var fn = route.callbacks[i++]; _$jscoverage['router/index.js'][275]++; try { _$jscoverage['router/index.js'][276]++; if ("route" == err) { _$jscoverage['router/index.js'][277]++; nextRoute(); } else { _$jscoverage['router/index.js'][278]++; if (err && fn) { _$jscoverage['router/index.js'][279]++; if (fn.length < 4) { _$jscoverage['router/index.js'][279]++; return callbacks(err); } _$jscoverage['router/index.js'][280]++; fn(err, req, res, callbacks); } else { _$jscoverage['router/index.js'][281]++; if (fn) { _$jscoverage['router/index.js'][282]++; fn(req, res, callbacks); } else { _$jscoverage['router/index.js'][284]++; nextRoute(err); } } } } catch (err) { _$jscoverage['router/index.js'][287]++; callbacks(err); } } })(0); }); _$jscoverage['router/index.js'][301]++; Router.prototype._options = (function (req, res) { _$jscoverage['router/index.js'][302]++; var path = parse(req.url).pathname, body = this._optionsFor(path).join(","); _$jscoverage['router/index.js'][304]++; res.set("Allow", body).send(body); }); _$jscoverage['router/index.js'][315]++; Router.prototype._optionsFor = (function (path) { _$jscoverage['router/index.js'][316]++; var self = this; _$jscoverage['router/index.js'][317]++; return methods.filter((function (method) { _$jscoverage['router/index.js'][318]++; var routes = self.map[method]; _$jscoverage['router/index.js'][319]++; if (! routes || "options" == method) { _$jscoverage['router/index.js'][319]++; return; } _$jscoverage['router/index.js'][320]++; for (var i = 0, len = routes.length; i < len; ++i) { _$jscoverage['router/index.js'][321]++; if (routes[i].match(path)) { _$jscoverage['router/index.js'][321]++; return true; } } })).map((function (method) { _$jscoverage['router/index.js'][324]++; return method.toUpperCase(); })); }); _$jscoverage['router/index.js'][339]++; Router.prototype.match = (function (req, i, head) { _$jscoverage['router/index.js'][340]++; var method = req.method.toLowerCase(), url = parse(req.url), path = url.pathname, routes = this.map, i = i || 0, captures, route, keys; _$jscoverage['router/index.js'][351]++; if (! head && "head" == method) { _$jscoverage['router/index.js'][353]++; route = this.match(req, i, true); _$jscoverage['router/index.js'][354]++; if (route) { _$jscoverage['router/index.js'][354]++; return route; } _$jscoverage['router/index.js'][358]++; method = "get"; } _$jscoverage['router/index.js'][362]++; if (routes = routes[method]) { _$jscoverage['router/index.js'][365]++; for (var len = routes.length; i < len; ++i) { _$jscoverage['router/index.js'][366]++; route = routes[i]; _$jscoverage['router/index.js'][367]++; if (captures = route.match(path)) { _$jscoverage['router/index.js'][368]++; keys = route.keys; _$jscoverage['router/index.js'][369]++; route.params = []; _$jscoverage['router/index.js'][372]++; for (var j = 1, jlen = captures.length; j < jlen; ++j) { _$jscoverage['router/index.js'][373]++; var key = keys[j - 1], val = "string" == typeof captures[j]? decodeURIComponent(captures[j]): captures[j]; _$jscoverage['router/index.js'][377]++; if (key) { _$jscoverage['router/index.js'][378]++; route.params[key.name] = val; } else { _$jscoverage['router/index.js'][380]++; route.params.push(val); } } _$jscoverage['router/index.js'][385]++; req._route_index = i; _$jscoverage['router/index.js'][386]++; return route; } } } }); _$jscoverage['router/index.js'][402]++; Router.prototype.route = (function (method, path, callbacks) { _$jscoverage['router/index.js'][403]++; var app = this.app, method = method.toLowerCase(), callbacks = utils.flatten([].slice.call(arguments, 2)); _$jscoverage['router/index.js'][408]++; if (! path) { _$jscoverage['router/index.js'][408]++; throw new Error("Router#" + method + "() requires a path"); } _$jscoverage['router/index.js'][411]++; debug("defined %s %s", method, path); _$jscoverage['router/index.js'][412]++; var route = new Route(method, path, callbacks, {sensitive: this.caseSensitive, strict: this.strict}); _$jscoverage['router/index.js'][418]++; (this.map[method] = this.map[method] || []).push(route); _$jscoverage['router/index.js'][419]++; this.routes.push(route); _$jscoverage['router/index.js'][420]++; return this; }); _$jscoverage['router/index.js'].source = ["/*!"," * Express - Router"," * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>"," * MIT Licensed"," */","","/**"," * Module dependencies."," */","","var Route = require('./route')"," , Collection = require('./collection')"," , utils = require('../utils')"," , debug = require('debug')('express:router')"," , parse = require('url').parse;","","/**"," * Expose `Router` constructor."," */","","exports = module.exports = Router;","","/**"," * Expose HTTP methods."," */","","var methods = exports.methods = require('./methods');","","/**"," * Initialize a new `Router` with the given `options`."," * "," * @param {Object} options"," * @api private"," */","","function Router(options) {"," options = options || {};"," var self = this;"," this.routes = new Collection;"," this.map = {};"," this.params = {};"," this._params = [];"," this.caseSensitive = options.caseSensitive;"," this.strict = options.strict;",""," this.middleware = function router(req, res, next){"," self._dispatch(req, res, next);"," };","}","","/**"," * Register a param callback `fn` for the given `name`."," *"," * @param {String|Function} name"," * @param {Function} fn"," * @return {Router} for chaining"," * @api public"," */","","Router.prototype.param = function(name, fn){"," // param logic"," if ('function' == typeof name) {"," this._params.push(name);"," return;"," }",""," // apply param functions"," var params = this._params"," , len = params.length"," , ret;",""," for (var i = 0; i < len; ++i) {"," if (ret = params[i](name, fn)) {"," fn = ret;"," }"," }",""," // ensure we end up with a"," // middleware function"," if ('function' != typeof fn) {"," throw new Error('invalid param() call for ' + name + ', got ' + fn);"," }",""," (this.params[name] = this.params[name] || []).push(fn);"," return this;","};","","/**"," * Return a `Collection` of all routes defined."," *"," * @return {Collection}"," * @api public"," */","","Router.prototype.all = function(){"," return this.find(function(){"," return true;"," });","};","","/**"," * Remove the given `route`, returns"," * a bool indicating if the route was present"," * or not."," *"," * @param {Route} route"," * @return {Boolean}"," * @api public"," */","","Router.prototype.remove = function(route){"," var routes = this.map[route.method]"," , len = routes.length;",""," // remove from array"," var i = this.routes.indexOf(route);"," this.routes.splice(i, 1);",""," // remove from map"," for (var i = 0; i < len; ++i) {"," if (route == routes[i]) {"," routes.splice(i, 1);"," return true;"," }"," }","};","","/**"," * Return routes with route paths matching `path`."," *"," * @param {String} method"," * @param {String} path"," * @return {Collection}"," * @api public"," */","","Router.prototype.lookup = function(method, path){"," return this.find(function(route){"," return path == route.path"," && (route.method == method"," || method == 'all');"," });","};","","// /**","// * Return routes with regexps that match the given `url`.","// *","// * @param {String} method","// * @param {String} url","// * @return {Collection}","// * @api public","// */","// ","// Router.prototype.match = function(method, url){","// return this.find(function(route){","// return route.match(url)","// && (route.method == method","// || method == 'all');","// });","// };","","/**"," * Find routes based on the return value of `fn`"," * which is invoked once per route."," *"," * @param {Function} fn"," * @return {Collection}"," * @api public"," */","","Router.prototype.find = function(fn){"," var len = methods.length"," , ret = new Collection(this)"," , method"," , routes"," , route;",""," for (var i = 0; i < len; ++i) {"," method = methods[i];"," routes = this.map[method];"," if (!routes) continue;"," for (var j = 0, jlen = routes.length; j < jlen; ++j) {"," route = routes[j];"," if (fn(route)) ret.push(route);"," }"," }",""," return ret;","};","","/**"," * Route dispatcher aka the route \"middleware\"."," *"," * @param {IncomingMessage} req"," * @param {ServerResponse} res"," * @param {Function} next"," * @api private"," */","","Router.prototype._dispatch = function(req, res, next){"," var params = this.params"," , self = this;",""," debug('dispatching %s %s', req.method, req.url);",""," // route dispatch"," (function pass(i, err){"," var paramCallbacks"," , paramIndex = 0"," , paramVal"," , route"," , keys"," , key"," , ret;",""," // match next route"," function nextRoute(err) {"," pass(req._route_index + 1, err);"," }",""," // match route"," req.route = route = self.match(req, i);",""," // implied OPTIONS"," if (!route && 'OPTIONS' == req.method) return self._options(req, res);",""," // no route"," if (!route) return next(err);"," debug('matched %s %s', route.method, route.path);",""," // we have a route"," // start at param 0"," req.params = route.params;"," keys = route.keys;"," i = 0;",""," // param callbacks"," function param(err) {"," paramIndex = 0;"," key = keys[i++];"," paramVal = key && req.params[key.name];"," paramCallbacks = key && params[key.name];",""," try {"," if ('route' == err) {"," nextRoute();"," } else if (err) {"," i = 0;"," callbacks(err);"," } else if (paramCallbacks && undefined !== paramVal) {"," paramCallback();"," } else if (key) {"," param();"," } else {"," i = 0;"," callbacks();"," }"," } catch (err) {"," param(err);"," }"," };",""," param(err);"," "," // single param callbacks"," function paramCallback(err) {"," var fn = paramCallbacks[paramIndex++];"," if (err || !fn) return param(err);"," fn(req, res, paramCallback, paramVal, key.name);"," }",""," // invoke route callbacks"," function callbacks(err) {"," var fn = route.callbacks[i++];"," try {"," if ('route' == err) {"," nextRoute();"," } else if (err && fn) {"," if (fn.length < 4) return callbacks(err);"," fn(err, req, res, callbacks);"," } else if (fn) {"," fn(req, res, callbacks);"," } else {"," nextRoute(err);"," }"," } catch (err) {"," callbacks(err);"," }"," }"," })(0);","};","","/**"," * Respond to __OPTIONS__ method."," *"," * @param {IncomingMessage} req"," * @param {ServerResponse} res"," * @api private"," */","","Router.prototype._options = function(req, res){"," var path = parse(req.url).pathname"," , body = this._optionsFor(path).join(',');"," res.set('Allow', body).send(body);","};","","/**"," * Return an array of HTTP verbs or \"options\" for `path`."," *"," * @param {String} path"," * @return {Array}"," * @api private"," */","","Router.prototype._optionsFor = function(path){"," var self = this;"," return methods.filter(function(method){"," var routes = self.map[method];"," if (!routes || 'options' == method) return;"," for (var i = 0, len = routes.length; i < len; ++i) {"," if (routes[i].match(path)) return true;"," }"," }).map(function(method){"," return method.toUpperCase();"," });","};","","/**"," * Attempt to match a route for `req`"," * with optional starting index of `i`"," * defaulting to 0."," *"," * @param {IncomingMessage} req"," * @param {Number} i"," * @return {Route}"," * @api private"," */","","Router.prototype.match = function(req, i, head){"," var method = req.method.toLowerCase()"," , url = parse(req.url)"," , path = url.pathname"," , routes = this.map"," , i = i || 0"," , captures"," , route"," , keys;",""," // HEAD support"," // TODO: clean this up"," if (!head && 'head' == method) {"," // attempt lookup"," route = this.match(req, i, true);"," if (route) return route;",""," // default to GET as res.render() / res.send()"," // etc support HEAD"," method = 'get';"," }",""," // routes for this method"," if (routes = routes[method]) {",""," // matching routes"," for (var len = routes.length; i < len; ++i) {"," route = routes[i];"," if (captures = route.match(path)) {"," keys = route.keys;"," route.params = [];",""," // params from capture groups"," for (var j = 1, jlen = captures.length; j < jlen; ++j) {"," var key = keys[j-1]"," , val = 'string' == typeof captures[j]"," ? decodeURIComponent(captures[j])"," : captures[j];"," if (key) {"," route.params[key.name] = val;"," } else {"," route.params.push(val);"," }"," }",""," // all done"," req._route_index = i;"," return route;"," }"," }"," }","};","","/**"," * Route `method`, `path`, and one or more callbacks."," *"," * @param {String} method"," * @param {String} path"," * @param {Function} callback..."," * @return {Router} for chaining"," * @api private"," */","","Router.prototype.route = function(method, path, callbacks){"," var app = this.app"," , method = method.toLowerCase()"," , callbacks = utils.flatten([].slice.call(arguments, 2));",""," // ensure path was given"," if (!path) throw new Error('Router#' + method + '() requires a path');",""," // create the route"," debug('defined %s %s', method, path);"," var route = new Route(method, path, callbacks, {"," sensitive: this.caseSensitive"," , strict: this.strict"," });",""," // add it"," (this.map[method] = this.map[method] || []).push(route);"," this.routes.push(route);"," return this;","};"]; package/lib-cov/router/methods.js000644 000765 000024 0000002172 11722507472015414 0ustar00000000 000000 /* automatically generated by JSCoverage - do not edit */ if (typeof _$jscoverage === 'undefined') _$jscoverage = {}; if (! _$jscoverage['router/methods.js']) { _$jscoverage['router/methods.js'] = []; _$jscoverage['router/methods.js'][12] = 0; } _$jscoverage['router/methods.js'][12]++; module.exports = ["get", "post", "put", "head", "delete", "options", "trace", "copy", "lock", "mkcol", "move", "propfind", "proppatch", "unlock", "report", "mkactivity", "checkout", "merge", "m-search", "notify", "subscribe", "unsubscribe", "patch"]; _$jscoverage['router/methods.js'].source = ["","/*!"," * Express - router - methods"," * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>"," * MIT Licensed"," */","","/**"," * HTTP methods supported by node."," */","","module.exports = ["," 'get'"," , 'post'"," , 'put'"," , 'head'"," , 'delete'"," , 'options'"," , 'trace'"," , 'copy'"," , 'lock'"," , 'mkcol'"," , 'move'"," , 'propfind'"," , 'proppatch'"," , 'unlock'"," , 'report'"," , 'mkactivity'"," , 'checkout'"," , 'merge'"," , 'm-search'"," , 'notify'"," , 'subscribe'"," , 'unsubscribe'"," , 'patch'","];"]; package/lib-cov/router/route.js000644 000765 000024 0000012123 11722507472015104 0ustar00000000 000000 /* automatically generated by JSCoverage - do not edit */ if (typeof _$jscoverage === 'undefined') _$jscoverage = {}; if (! _$jscoverage['router/route.js']) { _$jscoverage['router/route.js'] = []; _$jscoverage['router/route.js'][11] = 0; _$jscoverage['router/route.js'][29] = 0; _$jscoverage['router/route.js'][30] = 0; _$jscoverage['router/route.js'][31] = 0; _$jscoverage['router/route.js'][32] = 0; _$jscoverage['router/route.js'][33] = 0; _$jscoverage['router/route.js'][34] = 0; _$jscoverage['router/route.js'][48] = 0; _$jscoverage['router/route.js'][49] = 0; _$jscoverage['router/route.js'][69] = 0; _$jscoverage['router/route.js'][70] = 0; _$jscoverage['router/route.js'][71] = 0; _$jscoverage['router/route.js'][72] = 0; _$jscoverage['router/route.js'][73] = 0; _$jscoverage['router/route.js'][77] = 0; _$jscoverage['router/route.js'][78] = 0; _$jscoverage['router/route.js'][79] = 0; _$jscoverage['router/route.js'][88] = 0; } _$jscoverage['router/route.js'][11]++; module.exports = Route; _$jscoverage['router/route.js'][29]++; function Route(method, path, callbacks, options) { _$jscoverage['router/route.js'][30]++; options = options || {}; _$jscoverage['router/route.js'][31]++; this.path = path; _$jscoverage['router/route.js'][32]++; this.method = method; _$jscoverage['router/route.js'][33]++; this.callbacks = callbacks; _$jscoverage['router/route.js'][34]++; this.regexp = normalize(path, this.keys = [], options.sensitive, options.strict); } _$jscoverage['router/route.js'][48]++; Route.prototype.match = (function (path) { _$jscoverage['router/route.js'][49]++; return this.regexp.exec(path); }); _$jscoverage['router/route.js'][69]++; function normalize(path, keys, sensitive, strict) { _$jscoverage['router/route.js'][70]++; if (path instanceof RegExp) { _$jscoverage['router/route.js'][70]++; return path; } _$jscoverage['router/route.js'][71]++; if (path instanceof Array) { _$jscoverage['router/route.js'][72]++; path = "(" + path.join("|") + ")"; } _$jscoverage['router/route.js'][73]++; path = path.concat(strict? "": "/?").replace(/\/\(/g, "(?:/").replace(/(\/)?(\.)?:(\w+)(?:(\(.*?\)))?(\?)?/g, (function (_, slash, format, key, capture, optional) { _$jscoverage['router/route.js'][77]++; keys.push({name: key, optional: ! ! optional}); _$jscoverage['router/route.js'][78]++; slash = slash || ""; _$jscoverage['router/route.js'][79]++; return "" + (optional? "": slash) + "(?:" + (optional? slash: "") + (format || "") + (capture || (format && "([^/.]+?)" || "([^/]+?)")) + ")" + (optional || ""); })).replace(/([\/.])/g, "\\$1").replace(/\*/g, "(.*)"); _$jscoverage['router/route.js'][88]++; return new RegExp("^" + path + "$", sensitive? "": "i"); } _$jscoverage['router/route.js'].source = ["/*!"," * Express - router - Route"," * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>"," * MIT Licensed"," */","","/**"," * Expose `Route`."," */","","module.exports = Route;","","/**"," * Initialize `Route` with the given HTTP `method`, `path`,"," * and an array of `callbacks` and `options`."," *"," * Options:"," *"," * - `sensitive` enable case-sensitive routes"," * - `strict` enable strict matching for trailing slashes"," *"," * @param {String} method"," * @param {String} path"," * @param {Array} callbacks"," * @param {Object} options."," * @api private"," */","","function Route(method, path, callbacks, options) {"," options = options || {};"," this.path = path;"," this.method = method;"," this.callbacks = callbacks;"," this.regexp = normalize(path"," , this.keys = []"," , options.sensitive"," , options.strict);","}","","/**"," * Check if this route matches `path` and return captures made."," *"," * @param {String} path"," * @return {Array}"," * @api private"," */","","Route.prototype.match = function(path){"," return this.regexp.exec(path);","};","","/**"," * Normalize the given path string,"," * returning a regular expression."," *"," * An empty array should be passed,"," * which will contain the placeholder"," * key names. For example \"/user/:id\" will"," * then contain [\"id\"]."," *"," * @param {String|RegExp|Array} path"," * @param {Array} keys"," * @param {Boolean} sensitive"," * @param {Boolean} strict"," * @return {RegExp}"," * @api private"," */","","function normalize(path, keys, sensitive, strict) {"," if (path instanceof RegExp) return path;"," if (path instanceof Array) "," \tpath = '(' + path.join('|') + ')';"," path = path"," .concat(strict ? '' : '/?')"," .replace(/\\/\\(/g, '(?:/')"," .replace(/(\\/)?(\\.)?:(\\w+)(?:(\\(.*?\\)))?(\\?)?/g, function(_, slash, format, key, capture, optional){"," keys.push({ name: key, optional: !! optional });"," slash = slash || '';"," return ''"," + (optional ? '' : slash)"," + '(?:'"," + (optional ? slash : '')"," + (format || '') + (capture || (format && '([^/.]+?)' || '([^/]+?)')) + ')'"," + (optional || '');"," })"," .replace(/([\\/.])/g, '\\\\$1')"," .replace(/\\*/g, '(.*)');"," return new RegExp('^' + path + '$', sensitive ? '' : 'i');","}"]; package/lib-cov/utils.js000644 000765 000024 0000020247 11722507472013574 0ustar00000000 000000 /* automatically generated by JSCoverage - do not edit */ if (typeof _$jscoverage === 'undefined') _$jscoverage = {}; if (! _$jscoverage['utils.js']) { _$jscoverage['utils.js'] = []; _$jscoverage['utils.js'][12] = 0; _$jscoverage['utils.js'][22] = 0; _$jscoverage['utils.js'][23] = 0; _$jscoverage['utils.js'][24] = 0; _$jscoverage['utils.js'][35] = 0; _$jscoverage['utils.js'][36] = 0; _$jscoverage['utils.js'][38] = 0; _$jscoverage['utils.js'][39] = 0; _$jscoverage['utils.js'][40] = 0; _$jscoverage['utils.js'][42] = 0; _$jscoverage['utils.js'][45] = 0; _$jscoverage['utils.js'][58] = 0; _$jscoverage['utils.js'][60] = 0; _$jscoverage['utils.js'][63] = 0; _$jscoverage['utils.js'][66] = 0; _$jscoverage['utils.js'][69] = 0; _$jscoverage['utils.js'][74] = 0; _$jscoverage['utils.js'][75] = 0; _$jscoverage['utils.js'][76] = 0; _$jscoverage['utils.js'][79] = 0; _$jscoverage['utils.js'][91] = 0; _$jscoverage['utils.js'][92] = 0; _$jscoverage['utils.js'][108] = 0; _$jscoverage['utils.js'][109] = 0; _$jscoverage['utils.js'][112] = 0; _$jscoverage['utils.js'][113] = 0; _$jscoverage['utils.js'][114] = 0; _$jscoverage['utils.js'][115] = 0; _$jscoverage['utils.js'][129] = 0; _$jscoverage['utils.js'][130] = 0; _$jscoverage['utils.js'][134] = 0; _$jscoverage['utils.js'][137] = 0; _$jscoverage['utils.js'][150] = 0; _$jscoverage['utils.js'][151] = 0; _$jscoverage['utils.js'][154] = 0; _$jscoverage['utils.js'][158] = 0; _$jscoverage['utils.js'][169] = 0; _$jscoverage['utils.js'][170] = 0; } _$jscoverage['utils.js'][12]++; var mime = require("mime"); _$jscoverage['utils.js'][22]++; exports.isAbsolute = (function (path) { _$jscoverage['utils.js'][23]++; if ("/" == path[0]) { _$jscoverage['utils.js'][23]++; return true; } _$jscoverage['utils.js'][24]++; if (":" == path[1] && "\\" == path[2]) { _$jscoverage['utils.js'][24]++; return true; } }); _$jscoverage['utils.js'][35]++; exports.flatten = (function (arr, ret) { _$jscoverage['utils.js'][36]++; var ret = ret || [], len = arr.length; _$jscoverage['utils.js'][38]++; for (var i = 0; i < len; ++i) { _$jscoverage['utils.js'][39]++; if (Array.isArray(arr[i])) { _$jscoverage['utils.js'][40]++; exports.flatten(arr[i], ret); } else { _$jscoverage['utils.js'][42]++; ret.push(arr[i]); } } _$jscoverage['utils.js'][45]++; return ret; }); _$jscoverage['utils.js'][58]++; exports.accepts = (function (type, str) { _$jscoverage['utils.js'][60]++; if (! str) { _$jscoverage['utils.js'][60]++; return true; } _$jscoverage['utils.js'][63]++; if (! ~ type.indexOf("/")) { _$jscoverage['utils.js'][63]++; type = mime.lookup(type); } _$jscoverage['utils.js'][66]++; type = type.split("/"); _$jscoverage['utils.js'][69]++; var accepted = exports.parseAccept(str), len = accepted.length, obj, ok; _$jscoverage['utils.js'][74]++; for (var i = 0; i < len; ++i) { _$jscoverage['utils.js'][75]++; obj = accepted[i]; _$jscoverage['utils.js'][76]++; if (exports.accept(type, obj)) { _$jscoverage['utils.js'][76]++; return true; } } _$jscoverage['utils.js'][79]++; return false; }); _$jscoverage['utils.js'][91]++; exports.accept = (function (type, other) { _$jscoverage['utils.js'][92]++; return (type[0] == other.type || "*" == other.type) && (type[1] == other.subtype || "*" == other.subtype); }); _$jscoverage['utils.js'][108]++; exports.parseAccept = (function (str) { _$jscoverage['utils.js'][109]++; return exports.parseQuality(str).map((function (obj) { _$jscoverage['utils.js'][112]++; var parts = obj.value.split("/"); _$jscoverage['utils.js'][113]++; obj.type = parts[0]; _$jscoverage['utils.js'][114]++; obj.subtype = parts[1]; _$jscoverage['utils.js'][115]++; return obj; })); }); _$jscoverage['utils.js'][129]++; exports.parseQuality = (function (str) { _$jscoverage['utils.js'][130]++; return str.split(/ *, */).map(quality).filter((function (obj) { _$jscoverage['utils.js'][134]++; return obj.quality; })).sort((function (a, b) { _$jscoverage['utils.js'][137]++; return b.quality - a.quality; })); }); _$jscoverage['utils.js'][150]++; function quality(str) { _$jscoverage['utils.js'][151]++; var parts = str.split(/ *; */), val = parts[0]; _$jscoverage['utils.js'][154]++; var q = parts[1]? parseFloat(parts[1].split(/ *= */)[1]): 1; _$jscoverage['utils.js'][158]++; return ({value: val, quality: q}); } _$jscoverage['utils.js'][169]++; exports.escape = (function (html) { _$jscoverage['utils.js'][170]++; return String(html).replace(/&/g, "&").replace(/"/g, """).replace(//g, ">"); }); _$jscoverage['utils.js'].source = ["","/*!"," * Express - utils"," * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>"," * MIT Licensed"," */","","/**"," * Module dependencies."," */","","var mime = require('mime');","","/**"," * Check if `path` looks absolute."," *"," * @param {String} path"," * @return {Boolean}"," * @api private"," */","","exports.isAbsolute = function(path){"," if ('/' == path[0]) return true;"," if (':' == path[1] && '\\\\' == path[2]) return true;","};","","/**"," * Flatten the given `arr`."," *"," * @param {Array} arr"," * @return {Array}"," * @api private"," */","","exports.flatten = function(arr, ret){"," var ret = ret || []"," , len = arr.length;"," for (var i = 0; i < len; ++i) {"," if (Array.isArray(arr[i])) {"," exports.flatten(arr[i], ret);"," } else {"," ret.push(arr[i]);"," }"," }"," return ret;","};","","/**"," * Check if `type` is acceptable based on"," * the given `str`."," *"," * @param {String} type"," * @param {String} str"," * @return {Boolean}"," * @api private"," */","","exports.accepts = function(type, str){"," // accept anything when Accept is not present"," if (!str) return true;",""," // resolve mime"," if (!~type.indexOf('/')) type = mime.lookup(type);",""," // split type/subtype"," type = type.split('/');",""," // parse"," var accepted = exports.parseAccept(str)"," , len = accepted.length"," , obj"," , ok;",""," for (var i = 0; i < len; ++i) {"," obj = accepted[i];"," if (exports.accept(type, obj)) return true;"," }",""," return false;","};","","/**"," * Check if `type` array is acceptable for `other`."," *"," * @param {Array} type"," * @param {Object} other"," * @return {Boolean}"," * @api private"," */","","exports.accept = function(type, other){"," return (type[0] == other.type || '*' == other.type)"," && (type[1] == other.subtype || '*' == other.subtype);","};","","/**"," * Parse accept `str`, returning"," * an array objects containing"," * `.type` and `.subtype` along"," * with the values provided by"," * `parseQuality()`."," *"," * @param {Type} name"," * @return {Type}"," * @api private"," */","","exports.parseAccept = function(str){"," return exports"," .parseQuality(str)"," .map(function(obj){"," var parts = obj.value.split('/');"," obj.type = parts[0];"," obj.subtype = parts[1];"," return obj;"," });","};","","/**"," * Parse quality `str`, returning an"," * array of objects with `.value` and"," * `.quality`."," *"," * @param {Type} name"," * @return {Type}"," * @api private"," */","","exports.parseQuality = function(str){"," return str"," .split(/ *, */)"," .map(quality)"," .filter(function(obj){"," return obj.quality;"," })"," .sort(function(a, b){"," return b.quality - a.quality;"," });","};","","/**"," * Parse quality `str` returning an"," * object with `.value` and `.quality`."," *"," * @param {String} str"," * @return {Object}"," * @api private"," */","","function quality(str) {"," var parts = str.split(/ *; */)"," , val = parts[0];",""," var q = parts[1]"," ? parseFloat(parts[1].split(/ *= */)[1])"," : 1;",""," return { value: val, quality: q };","}","","/**"," * Escape special characters in the given string of html."," *"," * @param {String} html"," * @return {String}"," * @api private"," */","","exports.escape = function(html) {"," return String(html)"," .replace(/&/g, '&amp;')"," .replace(/\"/g, '&quot;')"," .replace(/</g, '&lt;')"," .replace(/>/g, '&gt;');","};"]; package/lib-cov/view.js000644 000765 000024 0000011104 11722507472013376 0ustar00000000 000000 /* automatically generated by JSCoverage - do not edit */ if (typeof _$jscoverage === 'undefined') _$jscoverage = {}; if (! _$jscoverage['view.js']) { _$jscoverage['view.js'] = []; _$jscoverage['view.js'][12] = 0; _$jscoverage['view.js'][25] = 0; _$jscoverage['view.js'][41] = 0; _$jscoverage['view.js'][42] = 0; _$jscoverage['view.js'][43] = 0; _$jscoverage['view.js'][44] = 0; _$jscoverage['view.js'][45] = 0; _$jscoverage['view.js'][46] = 0; _$jscoverage['view.js'][47] = 0; _$jscoverage['view.js'][48] = 0; _$jscoverage['view.js'][49] = 0; _$jscoverage['view.js'][50] = 0; _$jscoverage['view.js'][61] = 0; _$jscoverage['view.js'][62] = 0; _$jscoverage['view.js'][65] = 0; _$jscoverage['view.js'][66] = 0; _$jscoverage['view.js'][69] = 0; _$jscoverage['view.js'][70] = 0; _$jscoverage['view.js'][81] = 0; _$jscoverage['view.js'][82] = 0; } _$jscoverage['view.js'][12]++; var path = require("path"), utils = require("./utils"), fs = require("fs"), dirname = path.dirname, basename = path.basename, extname = path.extname, exists = path.existsSync, join = path.join; _$jscoverage['view.js'][25]++; module.exports = View; _$jscoverage['view.js'][41]++; function View(name, options) { _$jscoverage['view.js'][42]++; options = options || {}; _$jscoverage['view.js'][43]++; this.name = name; _$jscoverage['view.js'][44]++; this.root = options.root; _$jscoverage['view.js'][45]++; var engines = options.engines; _$jscoverage['view.js'][46]++; this.defaultEngine = options.defaultEngine; _$jscoverage['view.js'][47]++; var ext = this.ext = extname(name); _$jscoverage['view.js'][48]++; if (! ext) { _$jscoverage['view.js'][48]++; name += (ext = this.ext = "." + this.defaultEngine); } _$jscoverage['view.js'][49]++; this.engine = engines[ext] || (engines[ext] = require(ext.slice(1)).__express); _$jscoverage['view.js'][50]++; this.path = this.lookup(name); } _$jscoverage['view.js'][61]++; View.prototype.lookup = (function (path) { _$jscoverage['view.js'][62]++; var ext = this.ext; _$jscoverage['view.js'][65]++; if (! utils.isAbsolute(path)) { _$jscoverage['view.js'][65]++; path = join(this.root, path); } _$jscoverage['view.js'][66]++; if (exists(path)) { _$jscoverage['view.js'][66]++; return path; } _$jscoverage['view.js'][69]++; path = join(dirname(path), basename(path, ext), "index" + ext); _$jscoverage['view.js'][70]++; if (exists(path)) { _$jscoverage['view.js'][70]++; return path; } }); _$jscoverage['view.js'][81]++; View.prototype.render = (function (options, fn) { _$jscoverage['view.js'][82]++; this.engine(this.path, options, fn); }); _$jscoverage['view.js'].source = ["","/*!"," * Express - View"," * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>"," * MIT Licensed"," */","","/**"," * Module dependencies."," */","","var path = require('path')"," , utils = require('./utils')"," , fs = require('fs')"," , dirname = path.dirname"," , basename = path.basename"," , extname = path.extname"," , exists = path.existsSync"," , join = path.join;","","/**"," * Expose `View`."," */","","module.exports = View;","","/**"," * Initialize a new `View` with the given `name`."," *"," * Options:"," *"," * - `defaultEngine` the default template engine name "," * - `engines` template engine require() cache "," * - `root` root path for view lookup "," *"," * @param {String} name"," * @param {Object} options"," * @api private"," */","","function View(name, options) {"," options = options || {};"," this.name = name;"," this.root = options.root;"," var engines = options.engines;"," this.defaultEngine = options.defaultEngine;"," var ext = this.ext = extname(name);"," if (!ext) name += (ext = this.ext = '.' + this.defaultEngine);"," this.engine = engines[ext] || (engines[ext] = require(ext.slice(1)).__express);"," this.path = this.lookup(name);","}","","/**"," * Lookup view by the given `path`"," *"," * @param {String} path"," * @return {String}"," * @api private"," */","","View.prototype.lookup = function(path){"," var ext = this.ext;",""," // <path>.<engine>"," if (!utils.isAbsolute(path)) path = join(this.root, path);"," if (exists(path)) return path;",""," // <path>/index.<engine>"," path = join(dirname(path), basename(path, ext), 'index' + ext);"," if (exists(path)) return path;","};","","/**"," * Render with the given `options` and callback `fn(err, str)`."," *"," * @param {Object} options"," * @param {Function} fn"," * @api private"," */","","View.prototype.render = function(options, fn){"," this.engine(this.path, options, fn);","};"]; package/LICENSE000644 000765 000024 0000002116 11705172724011542 0ustar00000000 000000 (The MIT License) Copyright (c) 2009-2011 TJ Holowaychuk Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.package/Makefile000644 000765 000024 0000001056 11736457113012201 0ustar00000000 000000 DOCS = $(shell find docs/*.md) HTMLDOCS = $(DOCS:.md=.html) TESTS = $(shell find test/*.test.js) test: @NODE_ENV=test ./node_modules/.bin/expresso $(TESTS) docs: $(HTMLDOCS) @ echo "... generating TOC" @./support/toc.js docs/guide.html %.html: %.md @echo "... $< -> $@" @markdown $< \ | cat docs/layout/head.html - docs/layout/foot.html \ > $@ site: rm -fr /tmp/docs \ && cp -fr docs /tmp/docs \ && git checkout gh-pages \ && cp -fr /tmp/docs/* . \ && echo "done" docclean: rm -f docs/*.{1,html} .PHONY: site test docs doccleanpackage/package.json000644 000765 000024 0000002207 11736457133013030 0ustar00000000 000000 { "name": "express", "description": "Sinatra inspired web development framework", "version": "2.5.9", "author": "TJ Holowaychuk ", "contributors": [ { "name": "TJ Holowaychuk", "email": "tj@vision-media.ca" }, { "name": "Aaron Heckmann", "email": "aaron.heckmann+github@gmail.com" }, { "name": "Ciaran Jessup", "email": "ciaranj@gmail.com" }, { "name": "Guillermo Rauch", "email": "rauchg@gmail.com" } ], "dependencies": { "connect": "1.x", "mime": "1.2.4", "qs": "0.4.x", "mkdirp": "0.3.0" }, "devDependencies": { "connect-form": "0.2.1", "ejs": "0.4.2", "expresso": "0.9.2", "hamljs": "0.6.x", "jade": "0.16.2", "stylus": "0.13.0", "should": "0.3.2", "express-messages": "0.0.2", "node-markdown": ">= 0.0.1", "connect-redis": ">= 0.0.1" }, "keywords": ["framework", "sinatra", "web", "rest", "restful"], "repository": "git://github.com/visionmedia/express", "main": "index", "bin": { "express": "./bin/express" }, "scripts": { "test": "make test", "prepublish" : "npm prune" }, "engines": { "node": ">= 0.4.1 < 0.7.0" } }package/Readme.md000644 000765 000024 0000011311 11736457113012253 0ustar00000000 000000 # Express Insanely fast (and small) server-side JavaScript web development framework built on [node](http://nodejs.org) and [Connect](http://github.com/senchalabs/connect). var app = express.createServer(); app.get('/', function(req, res){ res.send('Hello World'); }); app.listen(3000); ## Installation $ npm install express or to access the `express(1)` executable install globally: $ npm install -g express ## Quick Start The quickest way to get started with express is to utilize the executable `express(1)` to generate an application as shown below: Create the app: $ npm install -g express $ express /tmp/foo && cd /tmp/foo Install dependencies: $ npm install -d Start the server: $ node app.js ## Features * Robust routing * Redirection helpers * Dynamic view helpers * Content negotiation * Focus on high performance * View rendering and partials support * Environment based configuration * Session based flash notifications * Built on [Connect](http://github.com/senchalabs/connect) * High test coverage * Executable for generating applications quickly * Application level view options Via Connect: * Session support * Cache API * Mime helpers * ETag support * Persistent flash notifications * Cookie support * JSON-RPC * Logging * and _much_ more! ## Contributors The following are the major contributors of Express (in no specific order). * TJ Holowaychuk ([visionmedia](http://github.com/visionmedia)) * Ciaran Jessup ([ciaranj](http://github.com/ciaranj)) * Aaron Heckmann ([aheckmann](http://github.com/aheckmann)) * Guillermo Rauch ([guille](http://github.com/guille)) ## More Information * #express on freenode * [express-expose](http://github.com/visionmedia/express-expose) expose objects, functions, modules and more to client-side js with ease * [express-configure](http://github.com/visionmedia/express-configuration) async configuration support * [express-messages](http://github.com/visionmedia/express-messages) flash notification rendering helper * [express-namespace](http://github.com/visionmedia/express-namespace) namespaced route support * [express-params](https://github.com/visionmedia/express-params) param pre-condition functions * [express-mongoose](https://github.com/LearnBoost/express-mongoose) plugin for easy rendering of Mongoose async Query results * Follow [tjholowaychuk](http://twitter.com/tjholowaychuk) on twitter for updates * [Google Group](http://groups.google.com/group/express-js) for discussion * Visit the [Wiki](http://github.com/visionmedia/express/wiki) * [日本語ドキュメンテーション](http://hideyukisaito.com/doc/expressjs/) by [hideyukisaito](https://github.com/hideyukisaito) * Screencast - [Introduction](http://bit.ly/eRYu0O) * Screencast - [View Partials](http://bit.ly/dU13Fx) * Screencast - [Route Specific Middleware](http://bit.ly/hX4IaH) * Screencast - [Route Path Placeholder Preconditions](http://bit.ly/eNqmVs) ## Node Compatibility Express 1.x is compatible with node 0.2.x and connect < 1.0. Express 2.x is compatible with node 0.4.x or 0.6.x, and connect 1.x Express 3.x (master) will be compatible with node 0.6.x and connect 2.x ## Viewing Examples First install the dev dependencies to install all the example / test suite deps: $ npm install then run whichever tests you want: $ node examples/jade/app.js ## Running Tests To run the test suite first invoke the following command within the repo, installing the development dependencies: $ npm install then run the tests: $ make test ## License (The MIT License) Copyright (c) 2009-2011 TJ Holowaychuk <tj@vision-media.ca> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. package/test.js000644 000765 000024 0000001236 11736435422012055 0ustar00000000 000000 var express = require('./') , app = express(); var user = { name: 'Tobi' }; app.param('user_id', function(req, res, next, id){ console.log(id); }); app.get('/:user_id/post/:post_id', function(req, res){ res.send(req.params.user); }); app.get('*', function(req, res, next){ console.log('GET one'); next(); }); app.use(function(req, res, next){ console.log('use'); next(); }); app.get('*', one, two, function(req, res, next){ console.log('GET two'); res.send('hey\n'); }); function one(req, res, next) { console.log('middleware one'); next(); } function two(req, res, next) { console.log('middleware two'); next(); } app.listen(4000);