├── test ├── public │ ├── lazyload.js │ └── index.html ├── node_modules │ ├── .bin │ │ └── express │ └── express │ │ ├── index.js │ │ ├── node_modules │ │ ├── mime │ │ │ ├── index.js │ │ │ ├── node.types │ │ │ ├── package.json │ │ │ ├── test.js │ │ │ ├── README.md │ │ │ └── mime.js │ │ ├── connect │ │ │ ├── index.js │ │ │ ├── lib │ │ │ │ ├── public │ │ │ │ │ ├── favicon.ico │ │ │ │ │ ├── error.html │ │ │ │ │ └── style.css │ │ │ │ ├── middleware │ │ │ │ │ ├── responseTime.js │ │ │ │ │ ├── cookieParser.js │ │ │ │ │ ├── methodOverride.js │ │ │ │ │ ├── vhost.js │ │ │ │ │ ├── session │ │ │ │ │ │ ├── store.js │ │ │ │ │ │ ├── cookie.js │ │ │ │ │ │ ├── memory.js │ │ │ │ │ │ └── session.js │ │ │ │ │ ├── limit.js │ │ │ │ │ ├── favicon.js │ │ │ │ │ ├── bodyParser.js │ │ │ │ │ ├── profiler.js │ │ │ │ │ ├── basicAuth.js │ │ │ │ │ ├── errorHandler.js │ │ │ │ │ ├── compiler.js │ │ │ │ │ ├── logger.js │ │ │ │ │ ├── static.js │ │ │ │ │ ├── router.js │ │ │ │ │ └── session.js │ │ │ │ ├── patch.js │ │ │ │ ├── https.js │ │ │ │ ├── index.js │ │ │ │ ├── connect.js │ │ │ │ ├── http.js │ │ │ │ └── utils.js │ │ │ ├── .npmignore │ │ │ ├── test.js │ │ │ ├── package.json │ │ │ └── LICENSE │ │ └── qs │ │ │ ├── index.js │ │ │ ├── support │ │ │ ├── expresso │ │ │ │ ├── .gitignore │ │ │ │ ├── docs │ │ │ │ │ ├── layout │ │ │ │ │ │ ├── foot.html │ │ │ │ │ │ └── head.html │ │ │ │ │ └── index.md │ │ │ │ ├── lib │ │ │ │ │ ├── bar.js │ │ │ │ │ └── foo.js │ │ │ │ ├── .gitmodules │ │ │ │ ├── test │ │ │ │ │ ├── async.test.js │ │ │ │ │ ├── bar.test.js │ │ │ │ │ ├── foo.test.js │ │ │ │ │ ├── serial │ │ │ │ │ │ ├── async.test.js │ │ │ │ │ │ └── http.test.js │ │ │ │ │ ├── assert.test.js │ │ │ │ │ └── http.test.js │ │ │ │ ├── package.json │ │ │ │ ├── Makefile │ │ │ │ ├── Readme.md │ │ │ │ └── History.md │ │ │ └── should │ │ │ │ ├── index.js │ │ │ │ ├── Makefile │ │ │ │ ├── .gitmodules │ │ │ │ ├── package.json │ │ │ │ ├── History.md │ │ │ │ ├── examples │ │ │ │ └── runner.js │ │ │ │ ├── lib │ │ │ │ └── eql.js │ │ │ │ └── Readme.md │ │ │ ├── Makefile │ │ │ ├── .gitmodules │ │ │ ├── package.json │ │ │ ├── History.md │ │ │ ├── benchmark.js │ │ │ ├── examples.js │ │ │ ├── Readme.md │ │ │ ├── lib │ │ │ └── querystring.js │ │ │ └── test │ │ │ └── querystring.test.js │ │ ├── .npmignore │ │ ├── package.json │ │ ├── Makefile │ │ ├── lib │ │ ├── view │ │ │ ├── partial.js │ │ │ └── view.js │ │ ├── https.js │ │ ├── express.js │ │ ├── router │ │ │ ├── methods.js │ │ │ ├── route.js │ │ │ └── index.js │ │ ├── utils.js │ │ └── request.js │ │ ├── LICENSE │ │ └── Readme.md └── test.js ├── LICENSE ├── HISTORY └── README.md /test/public/lazyload.js: -------------------------------------------------------------------------------- 1 | ../../lazyload.js -------------------------------------------------------------------------------- /test/node_modules/.bin/express: -------------------------------------------------------------------------------- 1 | ../express/bin/express -------------------------------------------------------------------------------- /test/node_modules/express/index.js: -------------------------------------------------------------------------------- 1 | 2 | module.exports = require('./lib/express'); -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/mime/index.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./mime'); 2 | -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/connect/index.js: -------------------------------------------------------------------------------- 1 | 2 | module.exports = require('./lib/connect'); -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/qs/index.js: -------------------------------------------------------------------------------- 1 | 2 | module.exports = require('./lib/querystring'); -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/qs/support/expresso/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | lib-cov 3 | *.seed -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/qs/support/expresso/docs/layout/foot.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/qs/support/should/index.js: -------------------------------------------------------------------------------- 1 | 2 | module.exports = require('./lib/should'); -------------------------------------------------------------------------------- /test/node_modules/express/.npmignore: -------------------------------------------------------------------------------- 1 | .git* 2 | docs/ 3 | examples/ 4 | support/ 5 | test/ 6 | testing.js 7 | .DS_Store 8 | -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/mime/node.types: -------------------------------------------------------------------------------- 1 | application/mp4 m4p 2 | application/octet-stream bin buffer 3 | audio/mp4 m4a 4 | -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/qs/support/expresso/lib/bar.js: -------------------------------------------------------------------------------- 1 | 2 | exports.bar = function(msg){ 3 | return msg || 'bar'; 4 | }; -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/qs/support/should/Makefile: -------------------------------------------------------------------------------- 1 | 2 | test: 3 | @./support/expresso/bin/expresso \ 4 | -I lib 5 | 6 | .PHONY: test -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/qs/Makefile: -------------------------------------------------------------------------------- 1 | 2 | test: 3 | @./support/expresso/bin/expresso \ 4 | -I support \ 5 | -I lib 6 | 7 | .PHONY: test -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/qs/support/should/.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "support/expresso"] 2 | path = support/expresso 3 | url = git://github.com/visionmedia/expresso.git 4 | -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/connect/lib/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oxUnd/lazyload/master/test/node_modules/express/node_modules/connect/lib/public/favicon.ico -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/qs/support/expresso/.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "deps/jscoverage"] 2 | path = deps/jscoverage 3 | url = git://github.com/visionmedia/node-jscoverage.git 4 | -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/connect/.npmignore: -------------------------------------------------------------------------------- 1 | *.markdown 2 | *.md 3 | .git* 4 | Makefile 5 | benchmarks/ 6 | docs/ 7 | examples/ 8 | install.sh 9 | support/ 10 | test/ 11 | .DS_Store 12 | -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/qs/.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "support/expresso"] 2 | path = support/expresso 3 | url = git://github.com/visionmedia/expresso.git 4 | [submodule "support/should"] 5 | path = support/should 6 | url = git://github.com/visionmedia/should.js.git 7 | -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/qs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "qs", 3 | "description": "querystring parser", 4 | "version": "0.1.0", 5 | "repository": {}, 6 | "author": "TJ Holowaychuk (http://tjholowaychuk.com)", 7 | "main": "index", 8 | "engines": { "node": "*" } 9 | } -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/qs/support/expresso/test/async.test.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Module dependencies. 4 | */ 5 | 6 | var assert = require('assert'); 7 | 8 | setTimeout(function(){ 9 | exports['test async exports'] = function(){ 10 | assert.ok('wahoo'); 11 | }; 12 | }, 100); -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/qs/support/expresso/test/bar.test.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Module dependencies. 4 | */ 5 | 6 | var assert = require('assert') 7 | , bar = require('bar'); 8 | 9 | module.exports = { 10 | 'bar()': function(){ 11 | assert.equal('bar', bar.bar()); 12 | } 13 | }; -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/connect/lib/public/error.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | {error} 4 | 5 | 6 | 7 |
8 |

{title}

9 |

500 {error}

10 | 11 |
12 | 13 | -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/qs/support/expresso/lib/foo.js: -------------------------------------------------------------------------------- 1 | 2 | exports.foo = function(msg){ 3 | if (msg) { 4 | return msg; 5 | } else { 6 | return generateFoo(); 7 | } 8 | }; 9 | 10 | function generateFoo() { 11 | return 'foo'; 12 | } 13 | 14 | function Foo(msg){ 15 | this.msg = msg || 'foo'; 16 | } 17 | -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/qs/support/expresso/test/foo.test.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Module dependencies. 4 | */ 5 | 6 | var assert = require('assert') 7 | , foo = require('foo'); 8 | 9 | module.exports = { 10 | 'foo()': function(){ 11 | assert.equal('foo', foo.foo()); 12 | assert.equal('foo', foo.foo()); 13 | } 14 | }; -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/qs/support/should/package.json: -------------------------------------------------------------------------------- 1 | { "name": "should" 2 | , "description": "test framework agnostic BDD-style assertions" 3 | , "version": "0.0.4" 4 | , "author": "TJ Holowaychuk " 5 | , "keywords": ["test", "bdd", "assert"] 6 | , "main": "./lib/should.js" 7 | , "engines": { "node": ">= 0.2.0" } 8 | } -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/qs/support/expresso/package.json: -------------------------------------------------------------------------------- 1 | { "name": "expresso", 2 | "version": "0.7.2", 3 | "description": "TDD framework, light-weight, fast, CI-friendly", 4 | "author": "TJ Holowaychuk ", 5 | "bin": { 6 | "expresso": "./bin/expresso", 7 | "node-jscoverage": "./deps/jscoverage/node-jscoverage" 8 | }, 9 | "scripts": { 10 | "preinstall": "make deps/jscoverage/node-jscoverage" 11 | } 12 | } -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/mime/package.json: -------------------------------------------------------------------------------- 1 | { "name" : "mime" 2 | , "description" : "A comprehensive library for mime-type mapping" 3 | , "url" : "http://github.com/bentomas/node-mime" 4 | , "keywords" : ["util", "mime"] 5 | , "author" : "Benjamin Thomas " 6 | , "contributors" : [] 7 | , "dependencies" : [] 8 | , "lib" : "." 9 | , "main" : "mime.js" 10 | , "version" : "1.2.1" 11 | } 12 | -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/qs/support/should/History.md: -------------------------------------------------------------------------------- 1 | 2 | 0.0.4 / 2010-11-24 3 | ================== 4 | 5 | * Added `.ok` to assert truthfulness 6 | * Added `.arguments` 7 | * Fixed double required bug. [thanks dominictarr] 8 | 9 | 0.0.3 / 2010-11-19 10 | ================== 11 | 12 | * Added `true` / `false` assertions 13 | 14 | 0.0.2 / 2010-11-19 15 | ================== 16 | 17 | * Added chaining support 18 | 19 | 0.0.1 / 2010-11-19 20 | ================== 21 | 22 | * Initial release 23 | -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/connect/test.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Module dependencies. 4 | */ 5 | 6 | var connect = require('./'); 7 | 8 | var router = connect.router(function(app){ 9 | function one(req, res, next) { 10 | console.log('one'); 11 | next(); 12 | } 13 | 14 | function two(req, res, next) { 15 | console.log('two'); 16 | next(); 17 | } 18 | 19 | app.param('user', one, two); 20 | 21 | app.get('/user/:user', one, two, function(req, res){ 22 | res.end('yay'); 23 | }); 24 | }); 25 | 26 | connect(router).listen(3000); -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/connect/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "connect", 3 | "version": "1.4.0", 4 | "description": "High performance middleware framework", 5 | "keywords": ["framework", "web", "middleware", "connect", "rack"], 6 | "repository": "git://github.com/senchalabs/connect.git", 7 | "author": "TJ Holowaychuk (http://tjholowaychuk.com)", 8 | "repository": "git://github.com/senchalabs/connect", 9 | "dependencies": { 10 | "qs": ">= 0.0.6", 11 | "mime": ">= 0.0.1" 12 | }, 13 | "main": "index", 14 | "engines": { "node": ">= 0.4.1 < 0.5.0" } 15 | } -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/qs/History.md: -------------------------------------------------------------------------------- 1 | 2 | 0.1.0 / 2011-04-13 3 | ================== 4 | 5 | * Added jQuery-ish array support 6 | 7 | 0.0.7 / 2011-03-13 8 | ================== 9 | 10 | * Fixed; handle empty string and `== null` in `qs.parse()` [dmit] 11 | allows for convenient `qs.parse(url.parse(str).query)` 12 | 13 | 0.0.6 / 2011-02-14 14 | ================== 15 | 16 | * Fixed; support for implicit arrays 17 | 18 | 0.0.4 / 2011-02-09 19 | ================== 20 | 21 | * Fixed `+` as a space 22 | 23 | 0.0.3 / 2011-02-08 24 | ================== 25 | 26 | * Fixed case when right-hand value contains "]" 27 | 28 | 0.0.2 / 2011-02-07 29 | ================== 30 | 31 | * Fixed "=" presence in key 32 | 33 | 0.0.1 / 2011-02-07 34 | ================== 35 | 36 | * Initial release -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/qs/benchmark.js: -------------------------------------------------------------------------------- 1 | 2 | var old = require('querystring') 3 | , qs = require('./') 4 | , times = 100000; 5 | 6 | var start = new Date 7 | , n = times; 8 | 9 | while (n--) old.parse('foo=bar'); 10 | console.log('old simple: %dms', new Date - start); 11 | 12 | var start = new Date 13 | , n = times; 14 | 15 | while (n--) old.parse('user[name][first]=tj&user[name][last]=holowaychuk'); 16 | console.log('old nested: %dms', new Date - start); 17 | 18 | 19 | console.log(); 20 | 21 | 22 | var start = new Date 23 | , n = times; 24 | 25 | while (n--) qs.parse('foo=bar'); 26 | console.log('new simple: %dms', new Date - start); 27 | 28 | var start = new Date 29 | , n = times; 30 | 31 | while (n--) qs.parse('user[name][first]=tj&user[name][last]=holowaychuk'); 32 | console.log('new nested: %dms', new Date - start); -------------------------------------------------------------------------------- /test/node_modules/express/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "express", 3 | "description": "Sinatra inspired web development framework", 4 | "version": "2.3.3", 5 | "author": "TJ Holowaychuk ", 6 | "contributors": [ 7 | { "name": "TJ Holowaychuk", "email": "tj@vision-media.ca" }, 8 | { "name": "Aaron Heckmann", "email": "aaron.heckmann+github@gmail.com" }, 9 | { "name": "Ciaran Jessup", "email": "ciaranj@gmail.com" }, 10 | { "name": "Guillermo Rauch", "email": "rauchg@gmail.com" } 11 | ], 12 | "dependencies": { 13 | "connect": ">= 1.4.0 < 2.0.0", 14 | "mime": ">= 0.0.1", 15 | "qs": ">= 0.0.6" 16 | }, 17 | "keywords": ["framework", "sinatra", "web", "rest", "restful"], 18 | "repository": "git://github.com/visionmedia/express", 19 | "main": "index", 20 | "bin": { "express": "./bin/express" }, 21 | "engines": { "node": ">= 0.4.1 < 0.5.0" } 22 | } -------------------------------------------------------------------------------- /test/node_modules/express/Makefile: -------------------------------------------------------------------------------- 1 | 2 | DOCS = $(shell find docs/*.md) 3 | HTMLDOCS =$(DOCS:.md=.html) 4 | 5 | test: 6 | @NODE_ENV=test ./support/expresso/bin/expresso \ 7 | -I lib \ 8 | -I support \ 9 | -I support/connect/lib \ 10 | -I support/haml/lib \ 11 | -I support/jade/lib \ 12 | -I support/ejs/lib \ 13 | $(TESTFLAGS) \ 14 | test/*.test.js 15 | 16 | test-cov: 17 | @TESTFLAGS=--cov $(MAKE) test 18 | 19 | docs: $(HTMLDOCS) 20 | @ echo "... generating TOC" 21 | @./support/toc.js docs/guide.html 22 | 23 | %.html: %.md 24 | @echo "... $< -> $@" 25 | @markdown $< \ 26 | | cat docs/layout/head.html - docs/layout/foot.html \ 27 | > $@ 28 | 29 | site: 30 | rm -fr /tmp/docs \ 31 | && cp -fr docs /tmp/docs \ 32 | && git checkout gh-pages \ 33 | && cp -fr /tmp/docs/* . \ 34 | && echo "done" 35 | 36 | docclean: 37 | rm -f docs/*.{1,html} 38 | 39 | .PHONY: site test test-cov docs docclean -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/connect/lib/middleware/responseTime.js: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * Connect - responseTime 4 | * Copyright(c) 2011 TJ Holowaychuk 5 | * MIT Licensed 6 | */ 7 | 8 | /** 9 | * Adds the `X-Response-Time` header displaying the response 10 | * duration in milliseconds. 11 | * 12 | * @return {Function} 13 | * @api public 14 | */ 15 | 16 | module.exports = function responseTime(){ 17 | return function(req, res, next){ 18 | var writeHead = res.writeHead 19 | , start = new Date; 20 | 21 | if (res._responseTime) return next(); 22 | res._responseTime = true; 23 | 24 | // proxy writeHead to calculate duration 25 | res.writeHead = function(status, headers){ 26 | var duration = new Date - start; 27 | res.setHeader('X-Response-Time', duration + 'ms'); 28 | res.writeHead = writeHead; 29 | res.writeHead(status, headers); 30 | }; 31 | 32 | next(); 33 | }; 34 | }; 35 | -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/qs/support/expresso/test/serial/async.test.js: -------------------------------------------------------------------------------- 1 | 2 | var assert = require('assert') 3 | , setup = 0 4 | , order = []; 5 | 6 | module.exports = { 7 | setup: function(done){ 8 | ++setup; 9 | done(); 10 | }, 11 | 12 | a: function(done){ 13 | assert.equal(1, setup); 14 | order.push('a'); 15 | setTimeout(function(){ 16 | done(); 17 | }, 500); 18 | }, 19 | 20 | b: function(done){ 21 | assert.equal(2, setup); 22 | order.push('b'); 23 | setTimeout(function(){ 24 | done(); 25 | }, 200); 26 | }, 27 | 28 | c: function(done){ 29 | assert.equal(3, setup); 30 | order.push('c'); 31 | setTimeout(function(){ 32 | done(); 33 | }, 1000); 34 | }, 35 | 36 | d: function(){ 37 | assert.eql(order, ['a', 'b', 'c']); 38 | } 39 | }; -------------------------------------------------------------------------------- /test/node_modules/express/lib/view/partial.js: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * Express - view - Partial 4 | * Copyright(c) 2010 TJ Holowaychuk 5 | * MIT Licensed 6 | */ 7 | 8 | /** 9 | * Memory cache. 10 | */ 11 | 12 | var cache = {}; 13 | 14 | /** 15 | * Resolve partial object name from the view path. 16 | * 17 | * Examples: 18 | * 19 | * "user.ejs" becomes "user" 20 | * "forum thread.ejs" becomes "forumThread" 21 | * "forum/thread/post.ejs" becomes "post" 22 | * "blog-post.ejs" becomes "blogPost" 23 | * 24 | * @return {String} 25 | * @api private 26 | */ 27 | 28 | exports.resolveObjectName = function(view){ 29 | return cache[view] || (cache[view] = view 30 | .split('/') 31 | .slice(-1)[0] 32 | .split('.')[0] 33 | .replace(/^_/, '') 34 | .replace(/[^a-zA-Z0-9 ]+/g, ' ') 35 | .split(/ +/).map(function(word, i){ 36 | return i 37 | ? word[0].toUpperCase() + word.substr(1) 38 | : word; 39 | }).join('')); 40 | }; -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/qs/support/expresso/docs/layout/head.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Expresso - TDD Framework For Node 4 | 36 | 37 | 38 | 39 | Fork me on GitHub 40 | 41 |
42 |

Expresso

43 | -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/connect/lib/patch.js: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * Connect 4 | * Copyright(c) 2011 TJ Holowaychuk 5 | * MIT Licensed 6 | */ 7 | 8 | /** 9 | * Module dependencies. 10 | */ 11 | 12 | var http = require('http') 13 | , res = http.OutgoingMessage.prototype; 14 | 15 | // original setHeader() 16 | 17 | var setHeader = res.setHeader; 18 | 19 | /** 20 | * Set header `field` to `val`, special-casing 21 | * the `Set-Cookie` field for multiple support. 22 | * 23 | * @param {String} field 24 | * @param {String} val 25 | * @api public 26 | */ 27 | 28 | res.setHeader = function(field, val){ 29 | var key = field.toLowerCase() 30 | , prev; 31 | 32 | // special-case Set-Cookie 33 | if (this._headers && 'set-cookie' == key) { 34 | if (prev = this.getHeader(field)) { 35 | val = Array.isArray(prev) 36 | ? prev.concat(val) 37 | : [prev, val]; 38 | } 39 | // charset 40 | } else if ('content-type' == key && this.charset) { 41 | val += '; charset=' + this.charset; 42 | } 43 | 44 | return setHeader.call(this, field, val); 45 | }; -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/qs/examples.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Module dependencies. 4 | */ 5 | 6 | var qs = require('./'); 7 | 8 | var obj = qs.parse('foo'); 9 | require('inspect')(obj) 10 | 11 | var obj = qs.parse('foo=bar=baz'); 12 | require('inspect')(obj) 13 | 14 | var obj = qs.parse('users[]'); 15 | require('inspect')(obj) 16 | 17 | var obj = qs.parse('name=tj&email=tj@vision-media.ca'); 18 | require('inspect')(obj) 19 | 20 | var obj = qs.parse('users[]=tj&users[]=tobi&users[]=jane'); 21 | require('inspect')(obj) 22 | 23 | var obj = qs.parse('user[name][first]=tj&user[name][last]=holowaychuk'); 24 | require('inspect')(obj) 25 | 26 | var obj = qs.parse('users[][name][first]=tj&users[][name][last]=holowaychuk'); 27 | require('inspect')(obj) 28 | 29 | var obj = qs.parse('a=a&a=b&a=c'); 30 | require('inspect')(obj) 31 | 32 | var obj = qs.parse('user[tj]=tj&user[tj]=TJ'); 33 | require('inspect')(obj) 34 | 35 | var obj = qs.parse('user[names]=tj&user[names]=TJ&user[names]=Tyler'); 36 | require('inspect')(obj) 37 | 38 | var obj = qs.parse('user[name][first]=tj&user[name][first]=TJ'); 39 | require('inspect')(obj) -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/connect/lib/middleware/cookieParser.js: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * Connect - cookieParser 4 | * Copyright(c) 2010 Sencha Inc. 5 | * Copyright(c) 2011 TJ Holowaychuk 6 | * MIT Licensed 7 | */ 8 | 9 | /** 10 | * Module dependencies. 11 | */ 12 | 13 | var utils = require('./../utils'); 14 | 15 | /** 16 | * Parse _Cookie_ header and populate `req.cookies` 17 | * with an object keyed by the cookie names. 18 | * 19 | * Examples: 20 | * 21 | * connect.createServer( 22 | * connect.cookieParser() 23 | * , function(req, res, next){ 24 | * res.end(JSON.stringify(req.cookies)); 25 | * } 26 | * ); 27 | * 28 | * @return {Function} 29 | * @api public 30 | */ 31 | 32 | module.exports = function cookieParser(){ 33 | return function cookieParser(req, res, next) { 34 | var cookie = req.headers.cookie; 35 | if (req.cookies) return next(); 36 | req.cookies = {}; 37 | if (cookie) { 38 | try { 39 | req.cookies = utils.parseCookie(cookie); 40 | } catch (err) { 41 | return next(err); 42 | } 43 | } 44 | next(); 45 | }; 46 | }; -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/connect/lib/middleware/methodOverride.js: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * Connect - methodOverride 4 | * Copyright(c) 2010 Sencha Inc. 5 | * Copyright(c) 2011 TJ Holowaychuk 6 | * MIT Licensed 7 | */ 8 | 9 | /** 10 | * Provides faux HTTP method support. 11 | * 12 | * Pass an optional `key` to use when checking for 13 | * a method override, othewise defaults to _\_method_. 14 | * The original method is available via `req.originalMethod`. 15 | * 16 | * @param {String} key 17 | * @return {Function} 18 | * @api public 19 | */ 20 | 21 | module.exports = function methodOverride(key){ 22 | key = key || "_method"; 23 | return function methodOverride(req, res, next) { 24 | req.originalMethod = req.originalMethod || req.method; 25 | 26 | // req.body 27 | if (req.body && key in req.body) { 28 | req.method = req.body[key].toUpperCase(); 29 | delete req.body[key]; 30 | // check X-HTTP-Method-Override 31 | } else if (req.headers['x-http-method-override']) { 32 | req.method = req.headers['x-http-method-override'].toUpperCase(); 33 | } 34 | 35 | next(); 36 | }; 37 | }; 38 | 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011 Ryan Grove 2 | All rights reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the 'Software'), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | the Software, and to permit persons to whom the Software is furnished to do so, 9 | subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /test/node_modules/express/lib/https.js: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * Express - HTTPSServer 4 | * Copyright(c) 2010 TJ Holowaychuk 5 | * MIT Licensed 6 | */ 7 | 8 | /** 9 | * Module dependencies. 10 | */ 11 | 12 | var connect = require('connect') 13 | , HTTPServer = require('./http') 14 | , https = require('https'); 15 | 16 | /** 17 | * Expose `HTTPSServer`. 18 | */ 19 | 20 | exports = module.exports = HTTPSServer; 21 | 22 | /** 23 | * Server proto. 24 | */ 25 | 26 | var app = HTTPSServer.prototype; 27 | 28 | /** 29 | * Initialize a new `HTTPSServer` with the 30 | * given `options`, and optional `middleware`. 31 | * 32 | * @param {Object} options 33 | * @param {Array} middleware 34 | * @api public 35 | */ 36 | 37 | function HTTPSServer(options, middleware){ 38 | connect.HTTPSServer.call(this, options, []); 39 | this.init(middleware); 40 | }; 41 | 42 | /** 43 | * Inherit from `connect.HTTPSServer`. 44 | */ 45 | 46 | app.__proto__ = connect.HTTPSServer.prototype; 47 | 48 | // mixin HTTPServer methods 49 | 50 | Object.keys(HTTPServer.prototype).forEach(function(method){ 51 | app[method] = HTTPServer.prototype[method]; 52 | }); 53 | -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | /** 3 | Run this script with Node.js 0.4.x and browse to http://localhost:3000/ to 4 | see the test page for LazyLoad. 5 | **/ 6 | 7 | var express = require('express'), 8 | 9 | app = express.createServer( 10 | express.logger(), 11 | express.static(__dirname + '/public'), 12 | express.errorHandler({dumpExceptions: true, showStack: true}) 13 | ); 14 | 15 | function delayable(req, res, next) { 16 | setTimeout(next, req.param('delay', 0)); 17 | } 18 | 19 | app.get('/', function (req, res) { 20 | res.redirect('/index.html', 303); 21 | }); 22 | 23 | app.get('/css', delayable, function (req, res) { 24 | var num = req.param('num'); 25 | 26 | res.header('Content-Type', 'text/css; charset=utf-8'); 27 | res.send( 28 | '#css-status { background-color: ' + (num === '5' ? 'green' : 'red') + '; }\n' + 29 | '#n' + num + ' { width: 5px; }\n' 30 | ); 31 | }); 32 | 33 | app.get('/js', delayable, function (req, res) { 34 | res.header('Content-Type', 'application/javascript; charset=utf-8'); 35 | res.send('jslog("script ' + req.param('num') + ' executed");'); 36 | }); 37 | 38 | app.listen(3000); 39 | -------------------------------------------------------------------------------- /test/node_modules/express/LICENSE: -------------------------------------------------------------------------------- 1 | (The MIT License) 2 | 3 | Copyright (c) 2009-2011 TJ Holowaychuk 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | 'Software'), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/connect/LICENSE: -------------------------------------------------------------------------------- 1 | (The MIT License) 2 | 3 | Copyright (c) 2010 Sencha Inc. 4 | Copyright (c) 2011 LearnBoost 5 | Copyright (c) 2011 TJ Holowaychuk 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining 8 | a copy of this software and associated documentation files (the 9 | 'Software'), to deal in the Software without restriction, including 10 | without limitation the rights to use, copy, modify, merge, publish, 11 | distribute, sublicense, and/or sell copies of the Software, and to 12 | permit persons to whom the Software is furnished to do so, subject to 13 | the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be 16 | included in all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 19 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/connect/lib/https.js: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * Connect - HTTPServer 4 | * Copyright(c) 2010 Sencha Inc. 5 | * Copyright(c) 2011 TJ Holowaychuk 6 | * MIT Licensed 7 | */ 8 | 9 | /** 10 | * Module dependencies. 11 | */ 12 | 13 | var HTTPServer = require('./http').Server 14 | , https = require('https'); 15 | 16 | /** 17 | * Initialize a new `Server` with the given 18 | *`options` and `middleware`. The HTTPS api 19 | * is identical to the [HTTP](http.html) server, 20 | * however TLS `options` must be provided before 21 | * passing in the optional middleware. 22 | * 23 | * @params {Object} options 24 | * @params {Array} middleawre 25 | * @return {Server} 26 | * @api public 27 | */ 28 | 29 | var Server = exports.Server = function HTTPSServer(options, middleware) { 30 | this.stack = []; 31 | middleware.forEach(function(fn){ 32 | this.use(fn); 33 | }, this); 34 | https.Server.call(this, options, this.handle); 35 | }; 36 | 37 | /** 38 | * Inherit from `http.Server.prototype`. 39 | */ 40 | 41 | Server.prototype.__proto__ = https.Server.prototype; 42 | 43 | // mixin HTTPServer methods 44 | 45 | Object.keys(HTTPServer.prototype).forEach(function(method){ 46 | Server.prototype[method] = HTTPServer.prototype[method]; 47 | }); -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/connect/lib/public/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | padding: 80px 100px; 4 | font: 13px "Helvetica Neue", "Lucida Grande", "Arial"; 5 | background: #F8F8F8; 6 | background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#fff), to(#ECE9E9)); 7 | background: -moz-linear-gradient(top, #fff, #ECE9E9); 8 | color: #555; 9 | -webkit-font-smoothing: antialiased; 10 | } 11 | h1, h2, h3 { 12 | margin: 0; 13 | font-size: 22px; 14 | color: #343434; 15 | } 16 | h1 em, h2 em { 17 | padding: 0 5px; 18 | font-weight: normal; 19 | } 20 | h1 { 21 | font-size: 60px; 22 | } 23 | h2 { 24 | margin-top: 10px; 25 | } 26 | h3 { 27 | margin: 5px 0 10px 0; 28 | padding-bottom: 5px; 29 | border-bottom: 1px solid #eee; 30 | font-size: 18px; 31 | } 32 | ul { 33 | margin: 0; 34 | padding: 0; 35 | } 36 | ul li { 37 | margin: 5px 0; 38 | padding: 3px 8px; 39 | list-style: none; 40 | } 41 | ul li:hover { 42 | cursor: pointer; 43 | color: #2e2e2e; 44 | } 45 | ul li .path { 46 | padding-left: 5px; 47 | font-weight: bold; 48 | } 49 | ul li .line { 50 | padding-right: 5px; 51 | font-style: italic; 52 | } 53 | ul li:first-child .path { 54 | padding-left: 0; 55 | } 56 | p { 57 | line-height: 1.5; 58 | } 59 | #stacktrace { 60 | margin-top: 15px; 61 | } -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/qs/support/should/examples/runner.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Module dependencies. 4 | */ 5 | 6 | var should = require('../'); 7 | 8 | function test(name, fn){ 9 | try { 10 | fn(); 11 | } catch (err) { 12 | console.log(' \x1b[31m%s', name); 13 | console.log(' %s\x1b[0m', err.stack); 14 | return; 15 | } 16 | console.log(' √ \x1b[32m%s\x1b[0m', name); 17 | } 18 | 19 | function Point(x, y) { 20 | this.x = x; 21 | this.y = y; 22 | this.sub = function(other){ 23 | return new Point( 24 | this.x - other.x 25 | , this.y - other.y); 26 | } 27 | } 28 | 29 | console.log(); 30 | 31 | test('new Point(x, y)', function(){ 32 | var point = new Point(50, 100); 33 | point.should.be.an.instanceof(Point); 34 | point.should.have.property('x', 50); 35 | point.should.have.property('y', 100); 36 | }); 37 | 38 | test('Point#sub()', function(){ 39 | var a = new Point(50, 100) 40 | , b = new Point(20, 50); 41 | a.sub(b).should.be.an.instanceof(Point); 42 | a.sub(b).should.not.equal(a); 43 | a.sub(b).should.not.equal(b); 44 | a.sub(b).should.have.property('x', 30); 45 | a.sub(b).should.have.property('y', 50); 46 | }); 47 | 48 | test('Point#add()', function(){ 49 | var point = new Point(50, 100); 50 | point.should.respondTo('add'); 51 | }); 52 | 53 | console.log(); -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/connect/lib/middleware/vhost.js: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * Connect - vhost 4 | * Copyright(c) 2010 Sencha Inc. 5 | * Copyright(c) 2011 TJ Holowaychuk 6 | * MIT Licensed 7 | */ 8 | 9 | /** 10 | * Setup vhost for the given `hostname` and `server`. 11 | * 12 | * Examples: 13 | * 14 | * connect( 15 | * connect.vhost('foo.com', 16 | * connect.createServer(...middleware...) 17 | * ), 18 | * connect.vhost('bar.com', 19 | * connect.createServer(...middleware...) 20 | * ) 21 | * ); 22 | * 23 | * @param {String} hostname 24 | * @param {Server} server 25 | * @return {Function} 26 | * @api public 27 | */ 28 | 29 | module.exports = function vhost(hostname, server){ 30 | if (!hostname) throw new Error('vhost hostname required'); 31 | if (!server) throw new Error('vhost server required'); 32 | var regexp = new RegExp('^' + hostname.replace(/[*]/g, '(.*?)') + '$'); 33 | if (server.onvhost) server.onvhost(hostname); 34 | return function vhost(req, res, next){ 35 | if (!req.headers.host) return next(); 36 | var host = req.headers.host.split(':')[0]; 37 | if (req.subdomains = regexp.exec(host)) { 38 | req.subdomains = req.subdomains[0].split('.').slice(0, -1); 39 | server.emit("request", req, res, next); 40 | } else { 41 | next(); 42 | } 43 | }; 44 | }; 45 | -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/qs/support/expresso/Makefile: -------------------------------------------------------------------------------- 1 | 2 | PREFIX ?= /usr/local 3 | BIN = bin/expresso 4 | JSCOV = deps/jscoverage/node-jscoverage 5 | DOCS = docs/index.md 6 | HTMLDOCS = $(DOCS:.md=.html) 7 | 8 | test: $(BIN) 9 | @./$(BIN) -I lib --growl $(TEST_FLAGS) test/*.test.js 10 | 11 | test-cov: 12 | @./$(BIN) -I lib --cov $(TEST_FLAGS) test/*.test.js 13 | 14 | test-serial: 15 | @./$(BIN) --serial -I lib $(TEST_FLAGS) test/serial/*.test.js 16 | 17 | install: install-jscov install-expresso 18 | 19 | uninstall: 20 | rm -f $(PREFIX)/bin/expresso 21 | rm -f $(PREFIX)/bin/node-jscoverage 22 | 23 | install-jscov: $(JSCOV) 24 | install $(JSCOV) $(PREFIX)/bin 25 | 26 | install-expresso: 27 | install $(BIN) $(PREFIX)/bin 28 | 29 | $(JSCOV): 30 | cd deps/jscoverage && ./configure && make && mv jscoverage node-jscoverage 31 | 32 | clean: 33 | @cd deps/jscoverage && git clean -fd 34 | 35 | docs: docs/api.html $(HTMLDOCS) 36 | 37 | %.html: %.md 38 | @echo "... $< > $@" 39 | @ronn -5 --pipe --fragment $< \ 40 | | cat docs/layout/head.html - docs/layout/foot.html \ 41 | > $@ 42 | 43 | docs/api.html: bin/expresso 44 | dox \ 45 | --title "Expresso" \ 46 | --ribbon "http://github.com/visionmedia/expresso" \ 47 | --desc "Insanely fast TDD framework for [node](http://nodejs.org) featuring code coverage reporting." \ 48 | $< > $@ 49 | 50 | docclean: 51 | rm -f docs/*.html 52 | 53 | .PHONY: test test-cov install uninstall install-expresso install-jscov clean docs docclean -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/connect/lib/middleware/session/store.js: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * Connect - session - Store 4 | * Copyright(c) 2010 Sencha Inc. 5 | * Copyright(c) 2011 TJ Holowaychuk 6 | * MIT Licensed 7 | */ 8 | 9 | /** 10 | * Module dependencies. 11 | */ 12 | 13 | var Session = require('./session') 14 | , Cookie = require('./cookie') 15 | , utils = require('../../utils'); 16 | 17 | /** 18 | * Initialize abstract `Store`. 19 | * 20 | * @api private 21 | */ 22 | 23 | var Store = module.exports = function Store(options){}; 24 | 25 | /** 26 | * Re-generate the given requests's session. 27 | * 28 | * @param {IncomingRequest} req 29 | * @return {Function} fn 30 | * @api public 31 | */ 32 | 33 | Store.prototype.regenerate = function(req, fn){ 34 | var self = this; 35 | this.destroy(req.sessionID, function(err){ 36 | self.generate(req); 37 | fn(err); 38 | }); 39 | }; 40 | 41 | /** 42 | * Create session from JSON `sess` data. 43 | * 44 | * @param {IncomingRequest} req 45 | * @param {Object} sess 46 | * @return {Session} 47 | * @api private 48 | */ 49 | 50 | Store.prototype.createSession = function(req, sess){ 51 | var expires = sess.cookie.expires 52 | , orig = sess.cookie.originalMaxAge; 53 | sess.cookie = new Cookie(sess.cookie); 54 | if ('string' == typeof expires) sess.cookie.expires = new Date(expires); 55 | sess.cookie.originalMaxAge = orig; 56 | req.session = new Session(req, sess); 57 | req.session.resetLastAccess(); 58 | return req.session; 59 | }; -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/qs/support/expresso/test/serial/http.test.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Module dependencies. 4 | */ 5 | 6 | var assert = require('assert') 7 | , http = require('http'); 8 | 9 | var server = http.createServer(function(req, res){ 10 | if (req.method === 'GET') { 11 | if (req.url === '/delay') { 12 | setTimeout(function(){ 13 | res.writeHead(200, {}); 14 | res.end('delayed'); 15 | }, 200); 16 | } else { 17 | var body = JSON.stringify({ name: 'tj' }); 18 | res.writeHead(200, { 19 | 'Content-Type': 'application/json; charset=utf8', 20 | 'Content-Length': body.length 21 | }); 22 | res.end(body); 23 | } 24 | } else { 25 | var body = ''; 26 | req.setEncoding('utf8'); 27 | req.addListener('data', function(chunk){ body += chunk }); 28 | req.addListener('end', function(){ 29 | res.writeHead(200, {}); 30 | res.end(req.url + ' ' + body); 31 | }); 32 | } 33 | }); 34 | 35 | module.exports = { 36 | 'test assert.response()': function(done){ 37 | assert.response(server, { 38 | url: '/', 39 | method: 'GET' 40 | },{ 41 | body: '{"name":"tj"}', 42 | status: 200, 43 | headers: { 44 | 'Content-Type': 'application/json; charset=utf8' 45 | } 46 | }, done); 47 | } 48 | }; -------------------------------------------------------------------------------- /test/node_modules/express/lib/express.js: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * Express 4 | * Copyright(c) 2010 TJ Holowaychuk 5 | * MIT Licensed 6 | */ 7 | 8 | /** 9 | * Module dependencies. 10 | */ 11 | 12 | var connect = require('connect') 13 | , HTTPSServer = require('./https') 14 | , HTTPServer = require('./http') 15 | , Route = require('./router/route') 16 | 17 | /** 18 | * Re-export connect auto-loaders. 19 | * 20 | * This prevents the need to `require('connect')` in order 21 | * to access core middleware, so for example `express.logger()` instead 22 | * of `require('connect').logger()`. 23 | */ 24 | 25 | var exports = module.exports = connect.middleware; 26 | 27 | /** 28 | * Framework version. 29 | */ 30 | 31 | exports.version = '2.3.3'; 32 | 33 | /** 34 | * Shortcut for `new Server(...)`. 35 | * 36 | * @param {Function} ... 37 | * @return {Server} 38 | * @api public 39 | */ 40 | 41 | exports.createServer = function(options){ 42 | if ('object' == typeof options) { 43 | return new HTTPSServer(options, Array.prototype.slice.call(arguments, 1)); 44 | } else { 45 | return new HTTPServer(Array.prototype.slice.call(arguments)); 46 | } 47 | }; 48 | 49 | /** 50 | * Expose constructors. 51 | */ 52 | 53 | exports.HTTPServer = HTTPServer; 54 | exports.HTTPSServer = HTTPSServer; 55 | exports.Route = Route; 56 | 57 | /** 58 | * View extensions. 59 | */ 60 | 61 | require('./view'); 62 | 63 | /** 64 | * Response extensions. 65 | */ 66 | 67 | require('./response'); 68 | 69 | /** 70 | * Request extensions. 71 | */ 72 | 73 | require('./request'); 74 | 75 | // Error handler title 76 | 77 | exports.errorHandler.title = 'Express'; 78 | 79 | -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/qs/Readme.md: -------------------------------------------------------------------------------- 1 | 2 | # node-querystring 3 | 4 | query string parser for node supporting nesting, as it was removed from `0.3.x`, so this library provides the previous and commonly desired behaviour (and twice as fast). Used by [express](http://expressjs.com), [connect](http://senchalabs.github.com/connect) and others. 5 | 6 | ## Installation 7 | 8 | $ npm install qs 9 | 10 | ## Examples 11 | 12 | require('querystring').parse('user[name][first]=tj&user[email]=tj'); 13 | // => { user: { name: { first: 'tj' }}} 14 | 15 | ## License 16 | 17 | (The MIT License) 18 | 19 | Copyright (c) 2010 TJ Holowaychuk <tj@vision-media.ca> 20 | 21 | Permission is hereby granted, free of charge, to any person obtaining 22 | a copy of this software and associated documentation files (the 23 | 'Software'), to deal in the Software without restriction, including 24 | without limitation the rights to use, copy, modify, merge, publish, 25 | distribute, sublicense, and/or sell copies of the Software, and to 26 | permit persons to whom the Software is furnished to do so, subject to 27 | the following conditions: 28 | 29 | The above copyright notice and this permission notice shall be 30 | included in all copies or substantial portions of the Software. 31 | 32 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 33 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 34 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 35 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 36 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 37 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 38 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /test/node_modules/express/lib/router/methods.js: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * Express - router - methods 4 | * Copyright(c) 2010 TJ Holowaychuk 5 | * MIT Licensed 6 | */ 7 | 8 | /** 9 | * Hypertext Transfer Protocol -- HTTP/1.1 10 | * http://www.ietf.org/rfc/rfc2616.txt 11 | */ 12 | 13 | var RFC2616 = ['OPTIONS', 'GET', 'POST', 'PUT', 'DELETE', 'TRACE', 'CONNECT']; 14 | 15 | /** 16 | * HTTP Extensions for Distributed Authoring -- WEBDAV 17 | * http://www.ietf.org/rfc/rfc2518.txt 18 | */ 19 | 20 | var RFC2518 = ['PROPFIND', 'PROPPATCH', 'MKCOL', 'COPY', 'MOVE', 'LOCK', 'UNLOCK']; 21 | 22 | /** 23 | * Versioning Extensions to WebDAV 24 | * http://www.ietf.org/rfc/rfc3253.txt 25 | */ 26 | 27 | var RFC3253 = ['VERSION-CONTROL', 'REPORT', 'CHECKOUT', 'CHECKIN', 'UNCHECKOUT', 'MKWORKSPACE', 'UPDATE', 'LABEL', 'MERGE', 'BASELINE-CONTROL', 'MKACTIVITY']; 28 | 29 | /** 30 | * Ordered Collections Protocol (WebDAV) 31 | * http://www.ietf.org/rfc/rfc3648.txt 32 | */ 33 | 34 | var RFC3648 = ['ORDERPATCH']; 35 | 36 | /** 37 | * Web Distributed Authoring and Versioning (WebDAV) Access Control Protocol 38 | * http://www.ietf.org/rfc/rfc3744.txt 39 | */ 40 | 41 | var RFC3744 = ['ACL']; 42 | 43 | /** 44 | * Web Distributed Authoring and Versioning (WebDAV) SEARCH 45 | * http://www.ietf.org/rfc/rfc5323.txt 46 | */ 47 | 48 | var RFC5323 = ['SEARCH']; 49 | 50 | /** 51 | * PATCH Method for HTTP 52 | * http://www.ietf.org/rfc/rfc5789.txt 53 | */ 54 | 55 | var RFC5789 = ['PATCH']; 56 | 57 | /** 58 | * Expose the methods. 59 | */ 60 | 61 | module.exports = [].concat( 62 | RFC2616 63 | , RFC2518 64 | , RFC3253 65 | , RFC3648 66 | , RFC3744 67 | , RFC5323 68 | , RFC5789).map(function(method){ 69 | return method.toLowerCase(); 70 | }); 71 | -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/connect/lib/middleware/limit.js: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * Connect - limit 4 | * Copyright(c) 2011 TJ Holowaychuk 5 | * MIT Licensed 6 | */ 7 | 8 | /** 9 | * Limit request bodies to the given size in `bytes`. 10 | * 11 | * A string representation of the bytesize may also be passed, 12 | * for example "5mb", "200kb", "1gb", etc. 13 | * 14 | * Examples: 15 | * 16 | * var server = connect( 17 | * connect.limit('5.5mb') 18 | * ).listen(3000); 19 | * 20 | * TODO: pause EV_READ 21 | * 22 | * @param {Number|String} bytes 23 | * @return {Function} 24 | * @api public 25 | */ 26 | 27 | module.exports = function limit(bytes){ 28 | if ('string' == typeof bytes) bytes = parse(bytes); 29 | if ('number' != typeof bytes) throw new Error('limit() bytes required'); 30 | return function limit(req, res, next){ 31 | var received = 0 32 | , len = req.headers['content-length'] 33 | ? parseInt(req.headers['content-length'], 10) 34 | : null; 35 | 36 | // deny the request 37 | function deny() { 38 | req.destroy(); 39 | } 40 | 41 | // self-awareness 42 | if (req._limit) return next(); 43 | req._limit = true; 44 | 45 | // limit by content-length 46 | if (len && len > bytes) deny(); 47 | 48 | // limit 49 | req.on('data', function(chunk){ 50 | received += chunk.length; 51 | if (received > bytes) deny(); 52 | }); 53 | 54 | next(); 55 | }; 56 | }; 57 | 58 | /** 59 | * Parse byte `size` string. 60 | * 61 | * @param {String} size 62 | * @return {Number} 63 | * @api private 64 | */ 65 | 66 | function parse(size) { 67 | var parts = size.match(/^(\d+(?:\.\d+)?) *(kb|mb|gb)$/) 68 | , n = parseFloat(parts[1]) 69 | , type = parts[2]; 70 | 71 | var map = { 72 | kb: 1024 73 | , mb: 1024 * 1024 74 | , gb: 1024 * 1024 * 1024 75 | }; 76 | 77 | return map[type] * n; 78 | } -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/connect/lib/index.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * # Connect 4 | * 5 | * Connect is a middleware framework for node, 6 | * shipping with over 11 bundled middleware and a rich choice of 7 | * [3rd-party middleware](https://github.com/senchalabs/connect/wiki). 8 | * 9 | * Installation: 10 | * 11 | * $ npm install connect 12 | * 13 | * API: 14 | * 15 | * - [connect](connect.html) general 16 | * - [http](http.html) http server 17 | * - [https](https.html) https server 18 | * 19 | * Middleware: 20 | * 21 | * - [logger](middleware-logger.html) request logger with custom format support 22 | * - [basicAuth](middleware-basicAuth.html) basic http authentication 23 | * - [bodyParser](middleware-bodyParser.html) extensible request body parser 24 | * - [cookieParser](middleware-cookieParser.html) cookie parser 25 | * - [session](middleware-session.html) session management support with bundled [MemoryStore](middleware-session-memory.html) 26 | * - [compiler](middleware-compiler.html) static asset compiler (sass, less, coffee-script, etc) 27 | * - [methodOverride](middleware-methodOverride.html) faux HTTP method support 28 | * - [responseTime](middleware-responseTime.html) calculates response-time and exposes via X-Response-Time 29 | * - [router](middleware-router.html) provides rich Sinatra / Express-like routing 30 | * - [static](middleware-static.html) streaming static file server supporting `Range` and more 31 | * - [vhost](middleware-vhost.html) virtual host sub-domain mapping middleware 32 | * - [favicon](middleware-favicon.html) efficient favicon server (with default icon) 33 | * - [limit](middleware-limit.html) limit the bytesize of request bodies 34 | * - [profiler](middleware-profiler.html) request profiler reporting response-time, memory usage, etc 35 | * 36 | * Internals: 37 | * 38 | * - connect [utilities](utils.html) 39 | * - node monkey [patches](patch.html) 40 | * 41 | */ -------------------------------------------------------------------------------- /test/node_modules/express/lib/router/route.js: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * Express - router - Route 4 | * Copyright(c) 2010 TJ Holowaychuk 5 | * MIT Licensed 6 | */ 7 | 8 | /** 9 | * Expose `Route`. 10 | */ 11 | 12 | module.exports = Route; 13 | 14 | /** 15 | * Initialize `Route` with the given HTTP `method`, `path`, 16 | * and callback `fn` and `options`. 17 | * 18 | * Options: 19 | * 20 | * - `sensitive` enable case-sensitive routes 21 | * 22 | * @param {String} method 23 | * @param {String} path 24 | * @param {Function} fn 25 | * @param {Object} options. 26 | * @api private 27 | */ 28 | 29 | function Route(method, path, fn, options) { 30 | options = options || {}; 31 | this.callback = fn; 32 | this.path = path; 33 | this.regexp = normalize(path, this.keys = [], options.sensitive); 34 | this.method = method; 35 | } 36 | 37 | /** 38 | * Normalize the given path string, 39 | * returning a regular expression. 40 | * 41 | * An empty array should be passed, 42 | * which will contain the placeholder 43 | * key names. For example "/user/:id" will 44 | * then contain ["id"]. 45 | * 46 | * @param {String|RegExp} path 47 | * @param {Array} keys 48 | * @param {Boolean} sensitive 49 | * @return {RegExp} 50 | * @api private 51 | */ 52 | 53 | function normalize(path, keys, sensitive) { 54 | if (path instanceof RegExp) return path; 55 | path = path 56 | .concat('/?') 57 | .replace(/\/\(/g, '(?:/') 58 | .replace(/(\/)?(\.)?:(\w+)(?:(\(.*?\)))?(\?)?/g, function(_, slash, format, key, capture, optional){ 59 | keys.push(key); 60 | slash = slash || ''; 61 | return '' 62 | + (optional ? '' : slash) 63 | + '(?:' 64 | + (optional ? slash : '') 65 | + (format || '') + (capture || '([^/]+?)') + ')' 66 | + (optional || ''); 67 | }) 68 | .replace(/([\/.])/g, '\\$1') 69 | .replace(/\*/g, '(.+)'); 70 | return new RegExp('^' + path + '$', sensitive ? '' : 'i'); 71 | } -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/connect/lib/middleware/favicon.js: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * Connect - favicon 4 | * Copyright(c) 2010 Sencha Inc. 5 | * Copyright(c) 2011 TJ Holowaychuk 6 | * MIT Licensed 7 | */ 8 | 9 | /** 10 | * Module dependencies. 11 | */ 12 | 13 | var fs = require('fs') 14 | , utils = require('../utils'); 15 | 16 | /** 17 | * Favicon cache. 18 | */ 19 | 20 | var icon; 21 | 22 | /** 23 | * By default serves the connect favicon, or the favicon 24 | * located by the given `path`. 25 | * 26 | * Options: 27 | * 28 | * - `maxAge` cache-control max-age directive, defaulting to 1 day 29 | * 30 | * Examples: 31 | * 32 | * connect.createServer( 33 | * connect.favicon() 34 | * ); 35 | * 36 | * connect.createServer( 37 | * connect.favicon(__dirname + '/public/favicon.ico') 38 | * ); 39 | * 40 | * @param {String} path 41 | * @param {Object} options 42 | * @return {Function} 43 | * @api public 44 | */ 45 | 46 | module.exports = function favicon(path, options){ 47 | var options = options || {} 48 | , path = path || __dirname + '/../public/favicon.ico' 49 | , maxAge = options.maxAge || 86400000; 50 | 51 | return function favicon(req, res, next){ 52 | if ('/favicon.ico' == req.url) { 53 | if (icon) { 54 | res.writeHead(200, icon.headers); 55 | res.end(icon.body); 56 | } else { 57 | fs.readFile(path, function(err, buf){ 58 | if (err) return next(err); 59 | icon = { 60 | headers: { 61 | 'Content-Type': 'image/x-icon' 62 | , 'Content-Length': buf.length 63 | , 'ETag': '"' + utils.md5(buf) + '"' 64 | , 'Cache-Control': 'public, max-age=' + (maxAge / 1000) 65 | }, 66 | body: buf 67 | }; 68 | res.writeHead(200, icon.headers); 69 | res.end(icon.body); 70 | }); 71 | } 72 | } else { 73 | next(); 74 | } 75 | }; 76 | }; -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/qs/support/expresso/Readme.md: -------------------------------------------------------------------------------- 1 | 2 | # Expresso 3 | 4 | TDD framework for [nodejs](http://nodejs.org). 5 | 6 | ## Features 7 | 8 | - light-weight 9 | - intuitive async support 10 | - intuitive test runner executable 11 | - test coverage support and reporting 12 | - uses the _assert_ module 13 | - `assert.eql()` alias of `assert.deepEqual()` 14 | - `assert.response()` http response utility 15 | - `assert.includes()` 16 | - `assert.type()` 17 | - `assert.isNull()` 18 | - `assert.isUndefined()` 19 | - `assert.isNotNull()` 20 | - `assert.isDefined()` 21 | - `assert.match()` 22 | - `assert.length()` 23 | 24 | ## Installation 25 | 26 | To install both expresso _and_ node-jscoverage run: 27 | 28 | $ make install 29 | 30 | To install expresso alone (no build required) run: 31 | 32 | $ make install-expresso 33 | 34 | Install via npm: 35 | 36 | $ npm install expresso 37 | 38 | ## License 39 | 40 | (The MIT License) 41 | 42 | Copyright (c) 2010 TJ Holowaychuk <tj@vision-media.ca> 43 | 44 | Permission is hereby granted, free of charge, to any person obtaining 45 | a copy of this software and associated documentation files (the 46 | 'Software'), to deal in the Software without restriction, including 47 | without limitation the rights to use, copy, modify, merge, publish, 48 | distribute, sublicense, and/or sell copies of the Software, and to 49 | permit persons to whom the Software is furnished to do so, subject to 50 | the following conditions: 51 | 52 | The above copyright notice and this permission notice shall be 53 | included in all copies or substantial portions of the Software. 54 | 55 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 56 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 57 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 58 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 59 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 60 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 61 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 62 | -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/mime/test.js: -------------------------------------------------------------------------------- 1 | var mime = require('./mime'); 2 | exports["test mime lookup"] = function(test) { 3 | // easy 4 | test.equal('text/plain', mime.lookup('text.txt')); 5 | 6 | // hidden file or multiple periods 7 | test.equal('text/plain', mime.lookup('.text.txt')); 8 | 9 | // just an extension 10 | test.equal('text/plain', mime.lookup('.txt')); 11 | 12 | // just an extension without a dot 13 | test.equal('text/plain', mime.lookup('txt')); 14 | 15 | // default 16 | test.equal('application/octet-stream', mime.lookup('text.nope')); 17 | 18 | // fallback 19 | test.equal('fallback', mime.lookup('text.fallback', 'fallback')); 20 | 21 | test.finish(); 22 | }; 23 | 24 | exports["test extension lookup"] = function(test) { 25 | // easy 26 | test.equal('txt', mime.extension(mime.types.text)); 27 | test.equal('html', mime.extension(mime.types.htm)); 28 | test.equal('bin', mime.extension('application/octet-stream')); 29 | 30 | test.finish(); 31 | }; 32 | 33 | exports["test mime lookup uppercase"] = function(test) { 34 | // easy 35 | test.equal('text/plain', mime.lookup('TEXT.TXT')); 36 | 37 | // just an extension 38 | test.equal('text/plain', mime.lookup('.TXT')); 39 | 40 | // just an extension without a dot 41 | test.equal('text/plain', mime.lookup('TXT')); 42 | 43 | // default 44 | test.equal('application/octet-stream', mime.lookup('TEXT.NOPE')); 45 | 46 | // fallback 47 | test.equal('fallback', mime.lookup('TEXT.FALLBACK', 'fallback')); 48 | 49 | test.finish(); 50 | }; 51 | 52 | exports["test custom types"] = function(test) { 53 | test.equal('application/octet-stream', mime.lookup('file.buffer')); 54 | test.equal('audio/mp4', mime.lookup('file.m4a')); 55 | 56 | test.finish(); 57 | }; 58 | 59 | exports["test charset lookup"] = function(test) { 60 | // easy 61 | test.equal('UTF-8', mime.charsets.lookup('text/plain')); 62 | 63 | // none 64 | test.ok(typeof mime.charsets.lookup(mime.types.js) == 'undefined'); 65 | 66 | // fallback 67 | test.equal('fallback', mime.charsets.lookup('application/octet-stream', 'fallback')); 68 | 69 | test.finish(); 70 | }; 71 | 72 | if (module == require.main) { 73 | require('async_testing').run(__filename, process.ARGV); 74 | } 75 | -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/mime/README.md: -------------------------------------------------------------------------------- 1 | # mime 2 | 3 | Support for mapping between file extensions and MIME types. This module uses the latest version of the Apache "mime.types" file (maps over 620 types to 800+ extensions). It is also trivially easy to add your own types and extensions, should you need to do that. 4 | 5 | ## Install 6 | 7 | Install with [npm](http://github.com/isaacs/npm): 8 | 9 | npm install mime 10 | 11 | ## API 12 | 13 | ### mime.lookup(path) - lookup the type for a file or extension 14 | 15 | var mime = require('mime'); 16 | 17 | mime.lookup('/path/to/file.txt'); // => 'text/plain' 18 | mime.lookup('file.txt'); // => 'text/plain' 19 | mime.lookup('.txt'); // => 'text/plain' 20 | mime.lookup('htm'); // => 'text/html' 21 | 22 | ### mime.extension(type) - lookup the default extension for type 23 | 24 | mime.extension('text/html'); // => 'html' 25 | mime.extension('application/octet-stream'); // => 'bin' 26 | 27 | ### mime.charsets.lookup() - map mime-type to charset 28 | 29 | mime.charsets.lookup('text/plain'); // => 'UTF-8' 30 | 31 | (The logic for charset lookups is pretty rudimentary. Feel free to suggest improvements.) 32 | 33 | ## "Can you add support for [some type/extension]?" 34 | 35 | Start by adding support for the type in your project using the mime.define() or mime.load() methods (documented below). 36 | 37 | If there's a type that is shared across node.js modules, by different people, create an issue here and we'll add it if it makes sense. 38 | 39 | If the type in question applies to projects outside the node.js community (e.g. if [IANA](http://www.iana.org/assignments/media-types/) approves a new type) file a [bug with Apache](http://httpd.apache.org/bug_report.html) and create an issue here that links to it. 40 | 41 | ### mime.define() - Add custom mime/extension mappings 42 | 43 | mime.define({ 44 | 'text/x-some-format': ['x-sf', 'x-sft', 'x-sfml'], 45 | 'application/x-my-type': ['x-mt', 'x-mtt'], 46 | // etc ... 47 | }); 48 | 49 | mime.lookup('x-sft'); // => 'text/x-some-format' 50 | mime.extension('text/x-some-format'); // => 'x-sf' 51 | 52 | ### mime.load(filepath) - Load mappings from an Apache ".types" format file 53 | 54 | mime.load('./my_project.types'); 55 | -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/connect/lib/middleware/bodyParser.js: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * Connect - bodyParser 4 | * Copyright(c) 2010 Sencha Inc. 5 | * Copyright(c) 2011 TJ Holowaychuk 6 | * MIT Licensed 7 | */ 8 | 9 | /** 10 | * Module dependencies. 11 | */ 12 | 13 | var qs = require('qs'); 14 | 15 | /** 16 | * Extract the mime type from the given request's 17 | * _Content-Type_ header. 18 | * 19 | * @param {IncomingMessage} req 20 | * @return {String} 21 | * @api private 22 | */ 23 | 24 | function mime(req) { 25 | var str = req.headers['content-type'] || ''; 26 | return str.split(';')[0]; 27 | } 28 | 29 | /** 30 | * Parse request bodies. 31 | * 32 | * By default _application/json_ and _application/x-www-form-urlencoded_ 33 | * are supported, however you may map `connect.bodyParser.parse[contentType]` 34 | * to a function of your choice to replace existing parsers, or implement 35 | * one for other content-types. 36 | * 37 | * Examples: 38 | * 39 | * connect.createServer( 40 | * connect.bodyParser() 41 | * , function(req, res) { 42 | * res.end('viewing user ' + req.body.user.name); 43 | * } 44 | * ); 45 | * 46 | * Since both _json_ and _x-www-form-urlencoded_ are supported by 47 | * default, either of the following requests would result in the response 48 | * of "viewing user tj". 49 | * 50 | * $ curl -d 'user[name]=tj' http://localhost/ 51 | * $ curl -d '{"user":{"name":"tj"}}' -H "Content-Type: application/json" http://localhost/ 52 | * 53 | * @return {Function} 54 | * @api public 55 | */ 56 | 57 | exports = module.exports = function bodyParser(){ 58 | return function bodyParser(req, res, next) { 59 | var parser = exports.parse[mime(req)]; 60 | if (parser && !req.body) { 61 | var data = ''; 62 | req.setEncoding('utf8'); 63 | req.on('data', function(chunk) { data += chunk; }); 64 | req.on('end', function(){ 65 | req.rawBody = data; 66 | try { 67 | req.body = data 68 | ? parser(data) 69 | : {}; 70 | } catch (err) { 71 | return next(err); 72 | } 73 | next(); 74 | }); 75 | } else { 76 | next(); 77 | } 78 | } 79 | }; 80 | 81 | /** 82 | * Supported decoders. 83 | * 84 | * - application/x-www-form-urlencoded 85 | * - application/json 86 | */ 87 | 88 | exports.parse = { 89 | 'application/x-www-form-urlencoded': qs.parse 90 | , 'application/json': JSON.parse 91 | }; -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/connect/lib/middleware/profiler.js: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * Connect - profiler 4 | * Copyright(c) 2011 TJ Holowaychuk 5 | * MIT Licensed 6 | */ 7 | 8 | /** 9 | * Profile the duration of a request. 10 | * 11 | * Typically this middleware should be utilized 12 | * _above_ all others, as it proxies the `res.end()` 13 | * method, being first allows it to encapsulate all 14 | * other middleware. 15 | * 16 | * Example Output: 17 | * 18 | * GET / 19 | * response time 2ms 20 | * memory rss 52.00kb 21 | * memory vsize 2.07mb 22 | * heap before 3.76mb / 8.15mb 23 | * heap after 3.80mb / 8.15mb 24 | * 25 | * @api public 26 | */ 27 | 28 | module.exports = function profiler(){ 29 | return function(req, res, next){ 30 | var end = res.end 31 | , start = snapshot(); 32 | 33 | // state snapshot 34 | function snapshot() { 35 | return { 36 | mem: process.memoryUsage() 37 | , time: new Date 38 | }; 39 | } 40 | 41 | // proxy res.end() 42 | res.end = function(data, encoding){ 43 | res.end = end; 44 | res.end(data, encoding); 45 | compare(req, start, snapshot()) 46 | }; 47 | 48 | next(); 49 | } 50 | }; 51 | 52 | /** 53 | * Compare `start` / `end` snapshots. 54 | * 55 | * @param {IncomingRequest} req 56 | * @param {Object} start 57 | * @param {Object} end 58 | * @api private 59 | */ 60 | 61 | function compare(req, start, end) { 62 | console.log(); 63 | row(req.method, req.url); 64 | row('response time:', (end.time - start.time) + 'ms'); 65 | row('memory rss:', formatBytes(end.mem.rss - start.mem.rss)); 66 | row('memory vsize:', formatBytes(end.mem.vsize - start.mem.vsize)); 67 | row('heap before:', formatBytes(start.mem.heapUsed) + ' / ' + formatBytes(start.mem.heapTotal)); 68 | row('heap after:', formatBytes(end.mem.heapUsed) + ' / ' + formatBytes(end.mem.heapTotal)); 69 | console.log(); 70 | } 71 | 72 | /** 73 | * Row helper 74 | * 75 | * @param {String} key 76 | * @param {String} val 77 | * @api private 78 | */ 79 | 80 | function row(key, val) { 81 | console.log(' \033[90m%s\033[0m \033[36m%s\033[0m', key, val); 82 | } 83 | 84 | /** 85 | * Format byte-size. 86 | * 87 | * @param {Number} bytes 88 | * @return {String} 89 | * @api private 90 | */ 91 | 92 | function formatBytes(bytes) { 93 | var kb = 1024 94 | , mb = 1024 * kb 95 | , gb = 1024 * mb; 96 | if (bytes < kb) return bytes + 'b'; 97 | if (bytes < mb) return (bytes / kb).toFixed(2) + 'kb'; 98 | if (bytes < gb) return (bytes / mb).toFixed(2) + 'mb'; 99 | return (bytes / gb).toFixed(2) + 'gb'; 100 | }; 101 | -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/qs/support/expresso/test/assert.test.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Module dependencies. 4 | */ 5 | 6 | var assert = require('assert'); 7 | 8 | module.exports = { 9 | 'assert.eql()': function(){ 10 | assert.equal(assert.deepEqual, assert.eql); 11 | }, 12 | 13 | 'assert.type()': function(){ 14 | assert.type('foobar', 'string'); 15 | assert.type(2, 'number'); 16 | assert.throws(function(){ 17 | assert.type([1,2,3], 'string'); 18 | }); 19 | }, 20 | 21 | 'assert.includes()': function(){ 22 | assert.includes('some random string', 'dom'); 23 | assert.throws(function(){ 24 | assert.include('some random string', 'foobar'); 25 | }); 26 | 27 | assert.includes(['foo', 'bar'], 'bar'); 28 | assert.includes(['foo', 'bar'], 'foo'); 29 | assert.includes([1,2,3], 3); 30 | assert.includes([1,2,3], 2); 31 | assert.includes([1,2,3], 1); 32 | assert.throws(function(){ 33 | assert.includes(['foo', 'bar'], 'baz'); 34 | }); 35 | 36 | assert.throws(function(){ 37 | assert.includes({ wrong: 'type' }, 'foo'); 38 | }); 39 | }, 40 | 41 | 'assert.isNull()': function(){ 42 | assert.isNull(null); 43 | assert.throws(function(){ 44 | assert.isNull(undefined); 45 | }); 46 | assert.throws(function(){ 47 | assert.isNull(false); 48 | }); 49 | }, 50 | 51 | 'assert.isUndefined()': function(){ 52 | assert.isUndefined(undefined); 53 | assert.throws(function(){ 54 | assert.isUndefined(null); 55 | }); 56 | assert.throws(function(){ 57 | assert.isUndefined(false); 58 | }); 59 | }, 60 | 61 | 'assert.isNotNull()': function(){ 62 | assert.isNotNull(false); 63 | assert.isNotNull(undefined); 64 | assert.throws(function(){ 65 | assert.isNotNull(null); 66 | }); 67 | }, 68 | 69 | 'assert.isDefined()': function(){ 70 | assert.isDefined(false); 71 | assert.isDefined(null); 72 | assert.throws(function(){ 73 | assert.isDefined(undefined); 74 | }); 75 | }, 76 | 77 | 'assert.match()': function(){ 78 | assert.match('foobar', /foo(bar)?/); 79 | assert.throws(function(){ 80 | assert.match('something', /rawr/); 81 | }); 82 | }, 83 | 84 | 'assert.length()': function(){ 85 | assert.length('test', 4); 86 | assert.length([1,2,3,4], 4); 87 | assert.throws(function(){ 88 | assert.length([1,2,3], 4); 89 | }); 90 | } 91 | }; -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/mime/mime.js: -------------------------------------------------------------------------------- 1 | var path = require('path'), 2 | fs = require('fs'); 3 | 4 | var mime = module.exports = { 5 | /** Map of extension to mime type */ 6 | types: {}, 7 | 8 | /** Map of mime type to extension */ 9 | extensions :{}, 10 | 11 | /** 12 | * Define mimetype -> extension mappings. Each key is a mime-type that maps 13 | * to an array of extensions associated with the type. The first extension is 14 | * used as the default extension for the type. 15 | * 16 | * e.g. mime.define({'audio/ogg', ['oga', 'ogg', 'spx']}); 17 | * 18 | * @param map (Object) type definitions 19 | */ 20 | define: function(map) { 21 | for (var type in map) { 22 | var exts = map[type]; 23 | 24 | for (var i = 0; i < exts.length; i++) { 25 | mime.types[exts[i]] = type; 26 | } 27 | 28 | mime.extensions[type] = exts[0]; 29 | } 30 | }, 31 | 32 | /** 33 | * Load an Apache2-style ".types" file 34 | * 35 | * This may be called multiple times (it's expected). Where files declare 36 | * overlapping types/extensions, the last file wins. 37 | * 38 | * @param file (String) path of file to load. 39 | */ 40 | load: function(file) { 41 | // Read file and split into lines 42 | var map = {}, 43 | content = fs.readFileSync(file, 'ascii'), 44 | lines = content.split(/[\r\n]+/); 45 | 46 | lines.forEach(function(line, lineno) { 47 | // Clean up whitespace/comments, and split into fields 48 | var fields = line.replace(/\s*#.*|^\s*|\s*$/g, '').split(/\s+/); 49 | map[fields.shift()] = fields; 50 | }); 51 | 52 | mime.define(map); 53 | }, 54 | 55 | /** 56 | * Lookup a mime type based on extension 57 | */ 58 | lookup: function(path, fallback) { 59 | var ext = path.replace(/.*[\.\/]/, '').toLowerCase(); 60 | return mime.types[ext] || fallback || mime.default_type; 61 | }, 62 | 63 | /** 64 | * Return file extension associated with a mime type 65 | */ 66 | extension: function(mimeType) { 67 | return mime.extensions[mimeType]; 68 | }, 69 | 70 | /** 71 | * Lookup a charset based on mime type. 72 | */ 73 | charsets: { 74 | lookup: function (mimeType, fallback) { 75 | // Assume text types are utf8. Modify mime logic as needed. 76 | return /^text\//.test(mimeType) ? 'UTF-8' : fallback; 77 | } 78 | } 79 | }; 80 | 81 | // Load our local copy of 82 | // http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types 83 | mime.load(path.join(__dirname, 'mime.types')); 84 | 85 | // Overlay enhancements we've had requests for (and that seem to make sense) 86 | mime.load(path.join(__dirname, 'node.types')); 87 | 88 | // Set the default type 89 | mime.default_type = mime.types.bin; 90 | -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/connect/lib/middleware/session/cookie.js: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * Connect - session - Cookie 4 | * Copyright(c) 2010 Sencha Inc. 5 | * Copyright(c) 2011 TJ Holowaychuk 6 | * MIT Licensed 7 | */ 8 | 9 | /** 10 | * Module dependencies. 11 | */ 12 | 13 | var utils = require('../../utils'); 14 | 15 | /** 16 | * Initialize a new `Cookie` with the given `options`. 17 | * 18 | * @param {Object} options 19 | * @api private 20 | */ 21 | 22 | var Cookie = module.exports = function Cookie(options) { 23 | this.path = '/'; 24 | this.httpOnly = true; 25 | this.maxAge = 14400000; 26 | if (options) utils.merge(this, options); 27 | this.originalMaxAge = undefined == this.originalMaxAge 28 | ? this.maxAge 29 | : this.originalMaxAge; 30 | }; 31 | 32 | /** 33 | * Prototype. 34 | */ 35 | 36 | Cookie.prototype = { 37 | 38 | /** 39 | * Set expires `date`. 40 | * 41 | * @param {Date} date 42 | * @api public 43 | */ 44 | 45 | set expires(date) { 46 | this._expires = date; 47 | this.originalMaxAge = this.maxAge; 48 | }, 49 | 50 | /** 51 | * Get expires `date`. 52 | * 53 | * @return {Date} 54 | * @api public 55 | */ 56 | 57 | get expires() { 58 | return this._expires; 59 | }, 60 | 61 | /** 62 | * Set expires via max-age in `ms`. 63 | * 64 | * @param {Number} ms 65 | * @api public 66 | */ 67 | 68 | set maxAge(ms) { 69 | this.expires = 'number' == typeof ms 70 | ? new Date(Date.now() + ms) 71 | : ms; 72 | }, 73 | 74 | /** 75 | * Get expires max-age in `ms`. 76 | * 77 | * @return {Number} 78 | * @api public 79 | */ 80 | 81 | get maxAge() { 82 | return this.expires instanceof Date 83 | ? this.expires.valueOf() - Date.now() 84 | : this.expires; 85 | }, 86 | 87 | /** 88 | * Return cookie data object. 89 | * 90 | * @return {Object} 91 | * @api private 92 | */ 93 | 94 | get data() { 95 | return { 96 | originalMaxAge: this.originalMaxAge 97 | , expires: this._expires 98 | , secure: this.secure 99 | , httpOnly: this.httpOnly 100 | , domain: this.domain 101 | , path: this.path 102 | } 103 | }, 104 | 105 | /** 106 | * Return a serialized cookie string. 107 | * 108 | * @return {String} 109 | * @api public 110 | */ 111 | 112 | serialize: function(name, val){ 113 | return utils.serializeCookie(name, val, this.data); 114 | }, 115 | 116 | /** 117 | * Return JSON representation of this cookie. 118 | * 119 | * @return {Object} 120 | * @api private 121 | */ 122 | 123 | toJSON: function(){ 124 | return this.data; 125 | } 126 | }; 127 | -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/connect/lib/middleware/basicAuth.js: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * Connect - basicAuth 4 | * Copyright(c) 2010 Sencha Inc. 5 | * Copyright(c) 2011 TJ Holowaychuk 6 | * MIT Licensed 7 | */ 8 | 9 | /** 10 | * Module dependencies. 11 | */ 12 | 13 | var utils = require('../utils') 14 | , unauthorized = utils.unauthorized 15 | , badRequest = utils.badRequest; 16 | 17 | /** 18 | * Enfore basic authentication by providing a `callback(user, pass)`, 19 | * which must return `true` in order to gain access. Alternatively an async 20 | * method is provided as well, invoking `callback(user, pass, callback)`. Populates 21 | * `req.remoteUser`. The final alternative is simply passing username / password 22 | * strings. 23 | * 24 | * Examples: 25 | * 26 | * connect(connect.basicAuth('username', 'password')); 27 | * 28 | * connect( 29 | * connect.basicAuth(function(user, pass){ 30 | * return 'tj' == user & 'wahoo' == pass; 31 | * }) 32 | * ); 33 | * 34 | * connect( 35 | * connect.basicAuth(function(user, pass, fn){ 36 | * User.authenticate({ user: user, pass: pass }, fn); 37 | * }) 38 | * ); 39 | * 40 | * @param {Function|String} callback or username 41 | * @param {String} realm 42 | * @api public 43 | */ 44 | 45 | module.exports = function basicAuth(callback, realm) { 46 | var username, password; 47 | 48 | // user / pass strings 49 | if ('string' == typeof callback) { 50 | username = callback; 51 | password = realm; 52 | if ('string' != typeof password) throw new Error('password argument required'); 53 | realm = arguments[2]; 54 | callback = function(user, pass){ 55 | return user == username && pass == password; 56 | } 57 | } 58 | 59 | realm = realm || 'Authorization Required'; 60 | 61 | return function(req, res, next) { 62 | var authorization = req.headers.authorization; 63 | 64 | if (req.remoteUser) return next(); 65 | if (!authorization) return unauthorized(res, realm); 66 | 67 | var parts = authorization.split(' ') 68 | , scheme = parts[0] 69 | , credentials = new Buffer(parts[1], 'base64').toString().split(':'); 70 | 71 | if ('Basic' != scheme) return badRequest(res); 72 | 73 | // async 74 | if (callback.length >= 3) { 75 | var pause = utils.pause(req); 76 | callback(credentials[0], credentials[1], function(err, user){ 77 | if (err || !user) return unauthorized(res, realm); 78 | req.remoteUser = user; 79 | next(); 80 | pause.resume(); 81 | }); 82 | // sync 83 | } else { 84 | if (callback(credentials[0], credentials[1])) { 85 | req.remoteUser = credentials[0]; 86 | next(); 87 | } else { 88 | unauthorized(res, realm); 89 | } 90 | } 91 | } 92 | }; 93 | 94 | -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/connect/lib/connect.js: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * Connect 4 | * Copyright(c) 2010 Sencha Inc. 5 | * Copyright(c) 2011 TJ Holowaychuk 6 | * MIT Licensed 7 | */ 8 | 9 | /** 10 | * Module dependencies. 11 | */ 12 | 13 | var HTTPServer = require('./http').Server 14 | , HTTPSServer = require('./https').Server 15 | , fs = require('fs'); 16 | 17 | // node patches 18 | 19 | require('./patch'); 20 | 21 | // expose createServer() as the module 22 | 23 | exports = module.exports = createServer; 24 | 25 | /** 26 | * Framework version. 27 | */ 28 | 29 | exports.version = '1.4.0'; 30 | 31 | /** 32 | * Initialize a new `connect.HTTPServer` with the middleware 33 | * passed to this function. When an object is passed _first_, 34 | * we assume these are the tls options, and return a `connect.HTTPSServer`. 35 | * 36 | * Examples: 37 | * 38 | * An example HTTP server, accepting several middleware. 39 | * 40 | * var server = connect.createServer( 41 | * connect.logger() 42 | * , connect.static(__dirname + '/public') 43 | * ); 44 | * 45 | * An HTTPS server, utilizing the same middleware as above. 46 | * 47 | * var server = connect.createServer( 48 | * { key: key, cert: cert } 49 | * , connect.logger() 50 | * , connect.static(__dirname + '/public') 51 | * ); 52 | * 53 | * Alternatively with connect 1.0 we may omit `createServer()`. 54 | * 55 | * connect( 56 | * connect.logger() 57 | * , connect.static(__dirname + '/public') 58 | * ).listen(3000); 59 | * 60 | * @param {Object|Function} ... 61 | * @return {Server} 62 | * @api public 63 | */ 64 | 65 | function createServer() { 66 | if ('object' == typeof arguments[0]) { 67 | return new HTTPSServer(arguments[0], Array.prototype.slice.call(arguments, 1)); 68 | } else { 69 | return new HTTPServer(Array.prototype.slice.call(arguments)); 70 | } 71 | }; 72 | 73 | // support connect.createServer() 74 | 75 | exports.createServer = createServer; 76 | 77 | // auto-load getters 78 | 79 | exports.middleware = {}; 80 | 81 | /** 82 | * Auto-load bundled middleware with getters. 83 | */ 84 | 85 | fs.readdirSync(__dirname + '/middleware').forEach(function(filename){ 86 | if (/\.js$/.test(filename)) { 87 | var name = filename.substr(0, filename.lastIndexOf('.')); 88 | exports.middleware.__defineGetter__(name, function(){ 89 | return require('./middleware/' + name); 90 | }); 91 | } 92 | }); 93 | 94 | // expose utils 95 | 96 | exports.utils = require('./utils'); 97 | 98 | // expose getters as first-class exports 99 | 100 | exports.utils.merge(exports, exports.middleware); 101 | 102 | // expose constructors 103 | 104 | exports.HTTPServer = HTTPServer; 105 | exports.HTTPSServer = HTTPSServer; 106 | 107 | -------------------------------------------------------------------------------- /test/node_modules/express/lib/utils.js: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * Express - Utils 4 | * Copyright(c) 2010 TJ Holowaychuk 5 | * MIT Licensed 6 | */ 7 | 8 | /** 9 | * Merge object `b` with `a` giving precedence to 10 | * values in object `a`. 11 | * 12 | * @param {Object} a 13 | * @param {Object} b 14 | * @return {Object} a 15 | * @api private 16 | */ 17 | 18 | exports.union = function(a, b){ 19 | if (a && b) { 20 | var keys = Object.keys(b) 21 | , len = keys.length 22 | , key; 23 | for (var i = 0; i < len; ++i) { 24 | key = keys[i]; 25 | if (!a.hasOwnProperty(key)) { 26 | a[key] = b[key]; 27 | } 28 | } 29 | } 30 | return a; 31 | }; 32 | 33 | /** 34 | * Flatten the given `arr`. 35 | * 36 | * @param {Array} arr 37 | * @return {Array} 38 | * @api private 39 | */ 40 | 41 | exports.flatten = function(arr, ret){ 42 | var ret = ret || [] 43 | , len = arr.length; 44 | for (var i = 0; i < len; ++i) { 45 | if (Array.isArray(arr[i])) { 46 | exports.flatten(arr[i], ret); 47 | } else { 48 | ret.push(arr[i]); 49 | } 50 | } 51 | return ret; 52 | }; 53 | 54 | /** 55 | * Parse mini markdown implementation. 56 | * The following conversions are supported, 57 | * primarily for the "flash" middleware: 58 | * 59 | * _foo_ or *foo* become foo 60 | * __foo__ or **foo** become foo 61 | * [A](B) becomes A 62 | * 63 | * @param {String} str 64 | * @return {String} 65 | * @api private 66 | */ 67 | 68 | exports.miniMarkdown = function(str){ 69 | return String(str) 70 | .replace(/(__|\*\*)(.*?)\1/g, '$2') 71 | .replace(/(_|\*)(.*?)\1/g, '$2') 72 | .replace(/\[([^\]]+)\]\(([^)]+)\)/g, '$1'); 73 | }; 74 | 75 | /** 76 | * Escape special characters in the given string of html. 77 | * 78 | * @param {String} html 79 | * @return {String} 80 | * @api private 81 | */ 82 | 83 | exports.escape = function(html) { 84 | return String(html) 85 | .replace(/&/g, '&') 86 | .replace(/"/g, '"') 87 | .replace(//g, '>'); 89 | }; 90 | 91 | /** 92 | * Parse "Range" header `str` relative to the given file `size`. 93 | * 94 | * @param {Number} size 95 | * @param {String} str 96 | * @return {Array} 97 | * @api private 98 | */ 99 | 100 | exports.parseRange = function(size, str){ 101 | var valid = true; 102 | var arr = str.substr(6).split(',').map(function(range){ 103 | var range = range.split('-') 104 | , start = parseInt(range[0], 10) 105 | , end = parseInt(range[1], 10); 106 | 107 | // -500 108 | if (isNaN(start)) { 109 | start = size - end; 110 | end = size - 1; 111 | // 500- 112 | } else if (isNaN(end)) { 113 | end = size - 1; 114 | } 115 | 116 | // Invalid 117 | if (isNaN(start) || isNaN(end) || start > end) valid = false; 118 | 119 | return { start: start, end: end }; 120 | }); 121 | return valid ? arr : undefined; 122 | }; 123 | -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/connect/lib/middleware/session/memory.js: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * Connect - session - MemoryStore 4 | * Copyright(c) 2010 Sencha Inc. 5 | * Copyright(c) 2011 TJ Holowaychuk 6 | * MIT Licensed 7 | */ 8 | 9 | /** 10 | * Module dependencies. 11 | */ 12 | 13 | var Store = require('./store') 14 | , utils = require('../../utils') 15 | , Session = require('./session'); 16 | 17 | /** 18 | * Initialize a new `MemoryStore`. 19 | * 20 | * @api public 21 | */ 22 | 23 | var MemoryStore = module.exports = function MemoryStore() { 24 | this.sessions = {}; 25 | }; 26 | 27 | /** 28 | * Inherit from `Store.prototype`. 29 | */ 30 | 31 | MemoryStore.prototype.__proto__ = Store.prototype; 32 | 33 | /** 34 | * Attempt to fetch session by the given `sid`. 35 | * 36 | * @param {String} sid 37 | * @param {Function} fn 38 | * @api public 39 | */ 40 | 41 | MemoryStore.prototype.get = function(sid, fn){ 42 | var self = this; 43 | process.nextTick(function(){ 44 | var expires 45 | , sess = self.sessions[sid]; 46 | if (sess) { 47 | sess = JSON.parse(sess); 48 | expires = 'string' == typeof sess.cookie.expires 49 | ? new Date(sess.cookie.expires) 50 | : sess.cookie.expires; 51 | if (!expires || new Date < expires) { 52 | fn(null, sess); 53 | } else { 54 | self.destroy(sid, fn); 55 | } 56 | } else { 57 | fn(); 58 | } 59 | }); 60 | }; 61 | 62 | /** 63 | * Commit the given `sess` object associated with the given `sid`. 64 | * 65 | * @param {String} sid 66 | * @param {Session} sess 67 | * @param {Function} fn 68 | * @api public 69 | */ 70 | 71 | MemoryStore.prototype.set = function(sid, sess, fn){ 72 | var self = this; 73 | process.nextTick(function(){ 74 | self.sessions[sid] = JSON.stringify(sess); 75 | fn && fn(); 76 | }); 77 | }; 78 | 79 | /** 80 | * Destroy the session associated with the given `sid`. 81 | * 82 | * @param {String} sid 83 | * @api public 84 | */ 85 | 86 | MemoryStore.prototype.destroy = function(sid, fn){ 87 | var self = this; 88 | process.nextTick(function(){ 89 | delete self.sessions[sid]; 90 | fn && fn(); 91 | }); 92 | }; 93 | 94 | /** 95 | * Invoke the given callback `fn` with all active sessions. 96 | * 97 | * @param {Function} fn 98 | * @api public 99 | */ 100 | 101 | MemoryStore.prototype.all = function(fn){ 102 | var arr = [] 103 | , keys = Object.keys(this.sessions); 104 | for (var i = 0, len = keys.length; i < len; ++i) { 105 | arr.push(this.sessions[keys[i]]); 106 | } 107 | fn(null, arr); 108 | }; 109 | 110 | /** 111 | * Clear all sessions. 112 | * 113 | * @param {Function} fn 114 | * @api public 115 | */ 116 | 117 | MemoryStore.prototype.clear = function(fn){ 118 | this.sessions = {}; 119 | fn && fn(); 120 | }; 121 | 122 | /** 123 | * Fetch number of sessions. 124 | * 125 | * @param {Function} fn 126 | * @api public 127 | */ 128 | 129 | MemoryStore.prototype.length = function(fn){ 130 | fn(null, Object.keys(this.sessions).length); 131 | }; 132 | -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/qs/support/should/lib/eql.js: -------------------------------------------------------------------------------- 1 | 2 | // Taken from node's assert module, because it sucks 3 | // and exposes next to nothing useful. 4 | 5 | module.exports = _deepEqual; 6 | 7 | function _deepEqual(actual, expected) { 8 | // 7.1. All identical values are equivalent, as determined by ===. 9 | if (actual === expected) { 10 | return true; 11 | 12 | } else if (Buffer.isBuffer(actual) && Buffer.isBuffer(expected)) { 13 | if (actual.length != expected.length) return false; 14 | 15 | for (var i = 0; i < actual.length; i++) { 16 | if (actual[i] !== expected[i]) return false; 17 | } 18 | 19 | return true; 20 | 21 | // 7.2. If the expected value is a Date object, the actual value is 22 | // equivalent if it is also a Date object that refers to the same time. 23 | } else if (actual instanceof Date && expected instanceof Date) { 24 | return actual.getTime() === expected.getTime(); 25 | 26 | // 7.3. Other pairs that do not both pass typeof value == "object", 27 | // equivalence is determined by ==. 28 | } else if (typeof actual != 'object' && typeof expected != 'object') { 29 | return actual == expected; 30 | 31 | // 7.4. For all other Object pairs, including Array objects, equivalence is 32 | // determined by having the same number of owned properties (as verified 33 | // with Object.prototype.hasOwnProperty.call), the same set of keys 34 | // (although not necessarily the same order), equivalent values for every 35 | // corresponding key, and an identical "prototype" property. Note: this 36 | // accounts for both named and indexed properties on Arrays. 37 | } else { 38 | return objEquiv(actual, expected); 39 | } 40 | } 41 | 42 | function isUndefinedOrNull (value) { 43 | return value === null || value === undefined; 44 | } 45 | 46 | function isArguments (object) { 47 | return Object.prototype.toString.call(object) == '[object Arguments]'; 48 | } 49 | 50 | function objEquiv (a, b) { 51 | if (isUndefinedOrNull(a) || isUndefinedOrNull(b)) 52 | return false; 53 | // an identical "prototype" property. 54 | if (a.prototype !== b.prototype) return false; 55 | //~~~I've managed to break Object.keys through screwy arguments passing. 56 | // Converting to array solves the problem. 57 | if (isArguments(a)) { 58 | if (!isArguments(b)) { 59 | return false; 60 | } 61 | a = pSlice.call(a); 62 | b = pSlice.call(b); 63 | return _deepEqual(a, b); 64 | } 65 | try{ 66 | var ka = Object.keys(a), 67 | kb = Object.keys(b), 68 | key, i; 69 | } catch (e) {//happens when one is a string literal and the other isn't 70 | return false; 71 | } 72 | // having the same number of owned properties (keys incorporates hasOwnProperty) 73 | if (ka.length != kb.length) 74 | return false; 75 | //the same set of keys (although not necessarily the same order), 76 | ka.sort(); 77 | kb.sort(); 78 | //~~~cheap key test 79 | for (i = ka.length - 1; i >= 0; i--) { 80 | if (ka[i] != kb[i]) 81 | return false; 82 | } 83 | //equivalent values for every corresponding key, and 84 | //~~~possibly expensive deep test 85 | for (i = ka.length - 1; i >= 0; i--) { 86 | key = ka[i]; 87 | if (!_deepEqual(a[key], b[key] )) 88 | return false; 89 | } 90 | return true; 91 | } 92 | -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/qs/lib/querystring.js: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * querystring 4 | * Copyright(c) 2010 TJ Holowaychuk 5 | * MIT Licensed 6 | */ 7 | 8 | /** 9 | * Library version. 10 | */ 11 | 12 | exports.version = '0.1.0'; 13 | 14 | /** 15 | * Parse the given query `str`, returning an object. 16 | * 17 | * @param {String} str 18 | * @return {Object} 19 | * @api public 20 | */ 21 | 22 | exports.parse = function(str) { 23 | if (str == undefined || str == '') return {}; 24 | 25 | return String(str) 26 | .split('&') 27 | .reduce(function(ret, pair){ 28 | var pair = decodeURIComponent(pair.replace(/\+/g, ' ')) 29 | , eql = pair.indexOf('=') 30 | , brace = lastBraceInKey(pair) 31 | , key = pair.substr(0, brace || eql) 32 | , val = pair.substr(brace || eql, pair.length) 33 | , val = val.substr(val.indexOf('=') + 1, val.length) 34 | , obj = ret; 35 | 36 | // ?foo 37 | if ('' == key) key = pair, val = ''; 38 | 39 | // nested 40 | if (~key.indexOf(']')) { 41 | var parts = key.split('[') 42 | , len = parts.length 43 | , last = len - 1; 44 | 45 | function parse(obj, parts, parent, key) { 46 | var part = parts.shift(); 47 | 48 | // end 49 | if (!part) { 50 | if (Array.isArray(parent[key])) { 51 | parent[key].push(val); 52 | } else if ('object' == typeof parent[key]) { 53 | parent[key] = val; 54 | } else { 55 | parent[key] = [parent[key], val]; 56 | } 57 | // array 58 | } else if (']' == part) { 59 | obj = parent[key] = Array.isArray(parent[key]) 60 | ? parent[key] 61 | : []; 62 | if ('' != val) obj.push(val); 63 | // prop 64 | } else if (~part.indexOf(']')) { 65 | part = part.substr(0, part.length - 1); 66 | parse(obj[part] = obj[part] || {}, parts, obj, part); 67 | // key 68 | } else { 69 | parse(obj[part] = obj[part] || {}, parts, obj, part); 70 | } 71 | } 72 | 73 | parse(obj, parts); 74 | // optimize 75 | } else { 76 | set(obj, key, val); 77 | } 78 | 79 | return ret; 80 | }, {}); 81 | }; 82 | 83 | /** 84 | * Set `obj`'s `key` to `val` respecting 85 | * the weird and wonderful syntax of a qs, 86 | * where "foo=bar&foo=baz" becomes an array. 87 | * 88 | * @param {Object} obj 89 | * @param {String} key 90 | * @param {String} val 91 | * @api private 92 | */ 93 | 94 | function set(obj, key, val) { 95 | var v = obj[key]; 96 | if (undefined === v) { 97 | obj[key] = val; 98 | } else if (Array.isArray(v)) { 99 | v.push(val); 100 | } else { 101 | obj[key] = [v, val]; 102 | } 103 | } 104 | 105 | /** 106 | * Locate last brace in `str` within the key. 107 | * 108 | * @param {String} str 109 | * @return {Number} 110 | * @api private 111 | */ 112 | 113 | function lastBraceInKey(str) { 114 | var len = str.length 115 | , brace 116 | , c; 117 | for (var i = 0; i < len; ++i) { 118 | c = str[i]; 119 | if (']' == c) brace = false; 120 | if ('[' == c) brace = true; 121 | if ('=' == c && !brace) return i; 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/connect/lib/middleware/errorHandler.js: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * Connect - errorHandler 4 | * Copyright(c) 2010 Sencha Inc. 5 | * Copyright(c) 2011 TJ Holowaychuk 6 | * MIT Licensed 7 | */ 8 | 9 | /** 10 | * Module dependencies. 11 | */ 12 | 13 | var utils = require('../utils') 14 | , url = require('url') 15 | , fs = require('fs'); 16 | 17 | /** 18 | * Flexible error handler, providing (_optional_) stack traces 19 | * and error message responses for requests accepting text, html, 20 | * or json. 21 | * 22 | * Options: 23 | * 24 | * - `showStack`, `stack` respond with both the error message and stack trace. Defaults to `false` 25 | * - `showMessage`, `message`, respond with the exception message only. Defaults to `false` 26 | * - `dumpExceptions`, `dump`, dump exceptions to stderr (without terminating the process). Defaults to `false` 27 | * 28 | * Text: 29 | * 30 | * By default, and when _text/plain_ is accepted a simple stack trace 31 | * or error message will be returned. 32 | * 33 | * JSON: 34 | * 35 | * When _application/json_ is accepted, connect will respond with 36 | * an object in the form of `{ "error": error }`. 37 | * 38 | * HTML: 39 | * 40 | * When accepted connect will output a nice html stack trace. 41 | * 42 | * @param {Object} options 43 | * @return {Function} 44 | * @api public 45 | */ 46 | 47 | exports = module.exports = function errorHandler(options){ 48 | options = options || {}; 49 | 50 | // defaults 51 | var showStack = options.showStack || options.stack 52 | , showMessage = options.showMessage || options.message 53 | , dumpExceptions = options.dumpExceptions || options.dump 54 | , formatUrl = options.formatUrl; 55 | 56 | return function errorHandler(err, req, res, next){ 57 | res.statusCode = 500; 58 | if (dumpExceptions) console.error(err.stack); 59 | if (showStack) { 60 | var accept = req.headers.accept || ''; 61 | // html 62 | if (~accept.indexOf('html')) { 63 | fs.readFile(__dirname + '/../public/style.css', 'utf8', function(e, style){ 64 | fs.readFile(__dirname + '/../public/error.html', 'utf8', function(e, html){ 65 | var stack = err.stack 66 | .split('\n').slice(1) 67 | .map(function(v){ return '
  • ' + v + '
  • '; }).join(''); 68 | html = html 69 | .replace('{style}', style) 70 | .replace('{stack}', stack) 71 | .replace('{title}', exports.title) 72 | .replace(/\{error\}/g, utils.escape(err.toString())); 73 | res.setHeader('Content-Type', 'text/html'); 74 | res.end(html); 75 | }); 76 | }); 77 | // json 78 | } else if (~accept.indexOf('json')) { 79 | var json = JSON.stringify({ error: err }); 80 | res.setHeader('Content-Type', 'application/json'); 81 | res.end(json); 82 | // plain text 83 | } else { 84 | res.writeHead(500, { 'Content-Type': 'text/plain' }); 85 | res.end(err.stack); 86 | } 87 | } else { 88 | var body = showMessage 89 | ? err.toString() 90 | : 'Internal Server Error'; 91 | res.setHeader('Content-Type', 'text/plain'); 92 | res.end(body); 93 | } 94 | }; 95 | }; 96 | 97 | /** 98 | * Template title. 99 | */ 100 | 101 | exports.title = 'Connect'; -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/connect/lib/middleware/session/session.js: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * Connect - session - Session 4 | * Copyright(c) 2010 Sencha Inc. 5 | * Copyright(c) 2011 TJ Holowaychuk 6 | * MIT Licensed 7 | */ 8 | 9 | /** 10 | * Module dependencies. 11 | */ 12 | 13 | var utils = require('../../utils') 14 | , Cookie = require('./cookie'); 15 | 16 | /** 17 | * Create a new `Session` with the given request and `data`. 18 | * 19 | * @param {IncomingRequest} req 20 | * @param {Object} data 21 | * @api private 22 | */ 23 | 24 | var Session = module.exports = function Session(req, data) { 25 | Object.defineProperty(this, 'req', { value: req }); 26 | Object.defineProperty(this, 'id', { value: req.sessionID }); 27 | if ('object' == typeof data) { 28 | utils.merge(this, data); 29 | } else { 30 | this.lastAccess = Date.now(); 31 | } 32 | }; 33 | 34 | /** 35 | * Update `.lastAccess` timestamp, 36 | * and reset `.cookie.maxAge` to prevent 37 | * the cookie from expiring when the 38 | * session is still active. 39 | * 40 | * @return {Session} for chaining 41 | * @api public 42 | */ 43 | 44 | Session.prototype.touch = function(){ 45 | return this 46 | .resetLastAccess() 47 | .resetMaxAge(); 48 | }; 49 | 50 | /** 51 | * Update `.lastAccess` timestamp. 52 | * 53 | * @return {Session} for chaining 54 | * @api public 55 | */ 56 | 57 | Session.prototype.resetLastAccess = function(){ 58 | this.lastAccess = Date.now(); 59 | return this; 60 | }; 61 | 62 | /** 63 | * Reset `.maxAge` to `.originalMaxAge`. 64 | * 65 | * @return {Session} for chaining 66 | * @api public 67 | */ 68 | 69 | Session.prototype.resetMaxAge = function(){ 70 | this.cookie.maxAge = this.cookie.originalMaxAge; 71 | return this; 72 | }; 73 | 74 | /** 75 | * Save the session data with optional callback `fn(err)`. 76 | * 77 | * @param {Function} fn 78 | * @return {Session} for chaining 79 | * @api public 80 | */ 81 | 82 | Session.prototype.save = function(fn){ 83 | this.req.sessionStore.set(this.id, this, fn || function(){}); 84 | return this; 85 | }; 86 | 87 | /** 88 | * Re-loads the session data _without_ altering 89 | * the maxAge or lastAccess properties. Invokes the 90 | * callback `fn(err)`, after which time if no exception 91 | * has occurred the `req.session` property will be 92 | * a new `Session` object, although representing the 93 | * same session. 94 | * 95 | * @param {Function} fn 96 | * @return {Session} for chaining 97 | * @api public 98 | */ 99 | 100 | Session.prototype.reload = function(fn){ 101 | var req = this.req 102 | , store = this.req.sessionStore; 103 | store.get(this.id, function(err, sess){ 104 | if (err) return fn(err); 105 | if (!sess) return fn(new Error('failed to load session')); 106 | store.createSession(req, sess); 107 | fn(); 108 | }); 109 | return this; 110 | }; 111 | 112 | /** 113 | * Destroy `this` session. 114 | * 115 | * @param {Function} fn 116 | * @return {Session} for chaining 117 | * @api public 118 | */ 119 | 120 | Session.prototype.destroy = function(fn){ 121 | delete this.req.session; 122 | this.req.sessionStore.destroy(this.id, fn); 123 | return this; 124 | }; 125 | 126 | /** 127 | * Regenerate this request's session. 128 | * 129 | * @param {Function} fn 130 | * @return {Session} for chaining 131 | * @api public 132 | */ 133 | 134 | Session.prototype.regenerate = function(fn){ 135 | this.req.sessionStore.regenerate(this.req, fn); 136 | return this; 137 | }; 138 | -------------------------------------------------------------------------------- /HISTORY: -------------------------------------------------------------------------------- 1 | LazyLoad Changelog 2 | ================================================================================ 3 | 4 | Version 2.0.3 (2011-07-05) 5 | * Fixed a bug caused by an unwanted Closure Compiler optimization that broke 6 | CSS load completion detection in Gecko when using the minified version of 7 | LazyLoad. [Allex Wang] 8 | * Fixed a race condition in which a URL could be removed from the "pending" 9 | queue if it finished loading before other URLs in the same batch had been 10 | added to the queue, resulting in the queue's length changing unexpectedly 11 | during iteration. [Klaas Neirinck] 12 | 13 | Version 2.0.2 (2011-04-17) 14 | * Added support for reliable detection of CSS load completion in Gecko 15 | browsers based on a technique described by Zach Leatherman at 16 | . 17 | * Fixed a bug that prevented CSS load completion from being detected in WebKit 18 | when there were no other stylesheets on the page. [Klaas Neirinck] 19 | * Fixed a bug that could prevent CSS callbacks from being called in IE. 20 | 21 | Version 2.0.1 (2011-03-05) 22 | * Added support for async=false. This ensures that parallel script loading 23 | still works in Firefox 4 while preserving execution order. For more info, 24 | see . 25 | * Stylesheet load completion is now detected reliably in WebKit by polling 26 | document.styleSheets for changes. Thanks to Jonathan Cook for suggesting 27 | this solution. 28 | * Dynamically created script and link nodes are now given a "lazyload" class 29 | so they can be identified later. 30 | * The charset for dynamically created script and link nodes is set to "utf-8". 31 | 32 | Version 2.0.0 (2009-08-06) 33 | * Added support for CSS. Caveat: Gecko and WebKit don't support the onload 34 | event for link nodes, so the CSS callback will fire almost immediately in 35 | those browsers. 36 | * When an array of URLs is specified, the resources will be loaded in parallel 37 | in browsers that support it. Currently, all browsers support loading CSS in 38 | parallel, but only Gecko and Opera support parallel scripts while preserving 39 | execution order. 40 | * The load() method has been replaced by css() and js() methods for loading 41 | CSS and JS, respectively. 42 | * The loadOnce() method has been removed, since it wasn't terribly useful. 43 | * Improved reliability in all supported browsers. 44 | 45 | Version 1.0.4 (2008-07-24) 46 | * Improved reliability with all supported browsers. 47 | * Reduced the minified size to 1751 bytes (a whopping 67 bytes smaller than 48 | version 1.0.3). 49 | * Fixed a bug that caused the load completion callback to fire immediately in 50 | Safari 3.x. 51 | * Fixed a bug that caused the load completion callback to fail to fire in 52 | Internet Explorer if the script was loaded from the cache. 53 | 54 | Version 1.0.3 (2007-06-18) 55 | * Added "force" parameter to the loadOnce() method to force execution of the 56 | callback even when all specified scripts have already been loaded. 57 | 58 | Version 1.0.2 (2007-06-02) 59 | * Improved browser detection. 60 | * Switched to NaturalDocs for source documentation. 61 | 62 | Version 1.0.1 (2007-05-30) 63 | * Fixed potential race condition when load() is called multiple times in 64 | succession. 65 | * Refactored to reduce complexity. 66 | 67 | Version 1.0.0 (2007-05-29) 68 | * First release. 69 | -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/qs/support/expresso/test/http.test.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Module dependencies. 4 | */ 5 | 6 | var assert = require('assert') 7 | , http = require('http'); 8 | 9 | var server = http.createServer(function(req, res){ 10 | if (req.method === 'GET') { 11 | if (req.url === '/delay') { 12 | setTimeout(function(){ 13 | res.writeHead(200, {}); 14 | res.end('delayed'); 15 | }, 200); 16 | } else { 17 | var body = JSON.stringify({ name: 'tj' }); 18 | res.writeHead(200, { 19 | 'Content-Type': 'application/json; charset=utf8', 20 | 'Content-Length': body.length 21 | }); 22 | res.end(body); 23 | } 24 | } else { 25 | var body = ''; 26 | req.setEncoding('utf8'); 27 | req.on('data', function(chunk){ body += chunk }); 28 | req.on('end', function(){ 29 | res.writeHead(200, {}); 30 | res.end(req.url + ' ' + body); 31 | }); 32 | } 33 | }); 34 | 35 | var delayedServer = http.createServer(function(req, res){ 36 | res.writeHead(200); 37 | res.end('it worked'); 38 | }); 39 | 40 | var oldListen = delayedServer.listen; 41 | delayedServer.listen = function(){ 42 | var args = arguments; 43 | setTimeout(function(){ 44 | oldListen.apply(delayedServer, args); 45 | }, 100); 46 | }; 47 | 48 | module.exports = { 49 | 'test assert.response(req, res, fn)': function(beforeExit){ 50 | var calls = 0; 51 | 52 | assert.response(server, { 53 | url: '/', 54 | method: 'GET' 55 | },{ 56 | body: '{"name":"tj"}', 57 | status: 200, 58 | headers: { 59 | 'Content-Type': 'application/json; charset=utf8' 60 | } 61 | }, function(res){ 62 | ++calls; 63 | assert.ok(res); 64 | }); 65 | 66 | beforeExit(function(){ 67 | assert.equal(1, calls); 68 | }) 69 | }, 70 | 71 | 'test assert.response(req, fn)': function(beforeExit){ 72 | var calls = 0; 73 | 74 | assert.response(server, { 75 | url: '/foo' 76 | }, function(res){ 77 | ++calls; 78 | assert.ok(res.body.indexOf('tj') >= 0, 'Test assert.response() callback'); 79 | }); 80 | 81 | beforeExit(function(){ 82 | assert.equal(1, calls); 83 | }); 84 | }, 85 | 86 | 'test assert.response() delay': function(beforeExit){ 87 | var calls = 0; 88 | 89 | assert.response(server, 90 | { url: '/delay', timeout: 1500 }, 91 | { body: 'delayed' }, 92 | function(){ 93 | ++calls; 94 | }); 95 | 96 | beforeExit(function(){ 97 | assert.equal(1, calls); 98 | }); 99 | }, 100 | 101 | 'test assert.response() regexp': function(beforeExit){ 102 | var calls = 0; 103 | 104 | assert.response(server, 105 | { url: '/foo', method: 'POST', data: 'foobar' }, 106 | { body: /^\/foo foo(bar)?/ }, 107 | function(){ 108 | ++calls; 109 | }); 110 | 111 | beforeExit(function(){ 112 | assert.equal(1, calls); 113 | }); 114 | }, 115 | 116 | 'test assert.response() regexp headers': function(beforeExit){ 117 | var calls = 0; 118 | 119 | assert.response(server, 120 | { url: '/' }, 121 | { body: '{"name":"tj"}', headers: { 'Content-Type': /^application\/json/ } }, 122 | function(){ 123 | ++calls; 124 | }); 125 | 126 | beforeExit(function(){ 127 | assert.equal(1, calls); 128 | }); 129 | }, 130 | 131 | // [!] if this test doesn't pass, an uncaught ECONNREFUSED will display 132 | 'test assert.response() with deferred listen()': function(beforeExit){ 133 | var calls = 0; 134 | 135 | assert.response(delayedServer, 136 | { url: '/' }, 137 | { body: 'it worked' }, 138 | function(){ 139 | ++calls; 140 | }); 141 | 142 | beforeExit(function(){ 143 | assert.equal(1, calls); 144 | }); 145 | } 146 | }; 147 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | LazyLoad 2 | ======== 3 | 4 | LazyLoad is a tiny (only 966 bytes minified and gzipped), dependency-free 5 | JavaScript utility that makes it super easy to load external JavaScript and CSS 6 | files on demand. 7 | 8 | Whenever possible, LazyLoad will automatically load resources in parallel while 9 | ensuring execution order when you specify an array of URLs to load. In browsers 10 | that don't preserve the execution order of asynchronously-loaded scripts, 11 | LazyLoad will safely load the scripts sequentially. 12 | 13 | Use LazyLoad when you need a small, fast, safe dynamic JS or CSS loader, but 14 | don't need the overhead of dependency management or other extra functionality 15 | that larger script loaders provide. 16 | 17 | Downloads 18 | --------- 19 | 20 | * [lazyload.js](https://github.com/rgrove/lazyload/raw/master/lazyload.js) (full source) 21 | 22 | Usage 23 | ----- 24 | 25 | Using LazyLoad is simple. Just call the appropriate method -- `css()` to load 26 | CSS, `js()` to load JavaScript -- and pass in a URL or array of URLs to load. 27 | You can also provide a callback function if you'd like to be notified when the 28 | resources have finished loading, as well as an argument to pass to the callback 29 | and a context in which to execute the callback. 30 | 31 | ```js 32 | // Load a single JavaScript file and execute a callback when it finishes. 33 | LazyLoad.js('http://example.com/foo.js', function () { 34 | alert('foo.js has been loaded'); 35 | }); 36 | 37 | // Load multiple JS files and execute a callback when they've all finished. 38 | LazyLoad.js(['foo.js', 'bar.js', 'baz.js'], function () { 39 | alert('all files have been loaded'); 40 | }); 41 | 42 | // Load a CSS file and pass an argument to the callback function. 43 | LazyLoad.css('foo.css', function (arg) { 44 | alert(arg); 45 | }, 'foo.css has been loaded'); 46 | 47 | // Load a CSS file and execute the callback in a different scope. 48 | LazyLoad.css('foo.css', function () { 49 | alert(this.foo); // displays 'bar' 50 | }, null, {foo: 'bar'}); 51 | ``` 52 | 53 | Supported Browsers 54 | ------------------ 55 | 56 | * Firefox 2+ 57 | * Google Chrome 58 | * Internet Explorer 6+ 59 | * Opera 9+ 60 | * Safari 3+ 61 | * Mobile Safari 62 | * Android 63 | 64 | Other browsers may work, but haven't been tested. It's a safe bet that anything 65 | based on a recent version of Gecko or WebKit will probably work. 66 | 67 | Caveats 68 | ------- 69 | 70 | All browsers support parallel loading of CSS. However, only Firefox and Opera 71 | currently support parallel script loading while preserving execution order. To 72 | ensure that scripts are always executed in the correct order, LazyLoad will load 73 | all scripts sequentially in browsers other than Firefox and Opera. Hopefully 74 | other browsers will improve their parallel script loading behavior soon. 75 | 76 | License 77 | ------- 78 | 79 | Copyright (c) 2011 Ryan Grove (ryan@wonko.com). 80 | All rights reserved. 81 | 82 | Permission is hereby granted, free of charge, to any person obtaining a copy of 83 | this software and associated documentation files (the 'Software'), to deal in 84 | the Software without restriction, including without limitation the rights to 85 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 86 | the Software, and to permit persons to whom the Software is furnished to do so, 87 | subject to the following conditions: 88 | 89 | The above copyright notice and this permission notice shall be included in all 90 | copies or substantial portions of the Software. 91 | 92 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 93 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 94 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 95 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 96 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 97 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 98 | -------------------------------------------------------------------------------- /test/node_modules/express/Readme.md: -------------------------------------------------------------------------------- 1 | 2 | # Express 3 | 4 | Insanely fast (and small) server-side JavaScript web development framework 5 | built on [node](http://nodejs.org) and [Connect](http://github.com/senchalabs/connect). 6 | 7 | var app = express.createServer(); 8 | 9 | app.get('/', function(req, res){ 10 | res.send('Hello World'); 11 | }); 12 | 13 | app.listen(3000); 14 | 15 | ## Installation 16 | 17 | $ npm install express 18 | 19 | or to access the `express(1)` executable install globally: 20 | 21 | $ npm install -g express 22 | 23 | ## Features 24 | 25 | * Robust routing 26 | * Redirection helpers 27 | * Dynamic view helpers 28 | * Content negotiation 29 | * Focus on high performance 30 | * View rendering and partials support 31 | * Environment based configuration 32 | * Session based flash notifications 33 | * Built on [Connect](http://github.com/senchalabs/connect) 34 | * High test coverage 35 | * Executable for generating applications quickly 36 | * Application level view options 37 | 38 | Via Connect: 39 | 40 | * Session support 41 | * Cache API 42 | * Mime helpers 43 | * ETag support 44 | * Persistent flash notifications 45 | * Cookie support 46 | * JSON-RPC 47 | * Logging 48 | * and _much_ more! 49 | 50 | ## Contributors 51 | 52 | The following are the major contributors of Express (in no specific order). 53 | 54 | * TJ Holowaychuk ([visionmedia](http://github.com/visionmedia)) 55 | * Ciaran Jessup ([ciaranj](http://github.com/ciaranj)) 56 | * Aaron Heckmann ([aheckmann](http://github.com/aheckmann)) 57 | * Guillermo Rauch ([guille](http://github.com/guille)) 58 | 59 | ## More Information 60 | 61 | * [express-expose](http://github.com/visionmedia/express-expose) expose objects, functions, modules and more to client-side js with ease 62 | * [express-configure](http://github.com/visionmedia/express-configuration) async configuration support 63 | * [express-messages](http://github.com/visionmedia/express-messages) flash notification rendering helper 64 | * [express-namespace](http://github.com/visionmedia/express-namespace) namespaced route support 65 | * Follow [tjholowaychuk](http://twitter.com/tjholowaychuk) on twitter for updates 66 | * [Google Group](http://groups.google.com/group/express-js) for discussion 67 | * Visit the [Wiki](http://github.com/visionmedia/express/wiki) 68 | * Screencast - [Introduction](http://bit.ly/eRYu0O) 69 | * Screencast - [View Partials](http://bit.ly/dU13Fx) 70 | * Screencast - [Route Specific Middleware](http://bit.ly/hX4IaH) 71 | * Screencast - [Route Path Placeholder Preconditions](http://bit.ly/eNqmVs) 72 | 73 | ## Node Compatibility 74 | 75 | Express 1.x is compatible with node 0.2.x and connect < 1.0. 76 | 77 | Express 2.x is compatible with node 0.4.x and connect 1.x 78 | 79 | ## License 80 | 81 | (The MIT License) 82 | 83 | Copyright (c) 2009-2011 TJ Holowaychuk <tj@vision-media.ca> 84 | 85 | Permission is hereby granted, free of charge, to any person obtaining 86 | a copy of this software and associated documentation files (the 87 | 'Software'), to deal in the Software without restriction, including 88 | without limitation the rights to use, copy, modify, merge, publish, 89 | distribute, sublicense, and/or sell copies of the Software, and to 90 | permit persons to whom the Software is furnished to do so, subject to 91 | the following conditions: 92 | 93 | The above copyright notice and this permission notice shall be 94 | included in all copies or substantial portions of the Software. 95 | 96 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 97 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 98 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 99 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 100 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 101 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 102 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 103 | -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/qs/support/expresso/History.md: -------------------------------------------------------------------------------- 1 | 2 | 0.7.2 / 2010-12-29 3 | ================== 4 | 5 | * Fixed problem with `listen()` sometimes firing on the same tick [guillermo] 6 | 7 | 0.7.1 / 2010-12-28 8 | ================== 9 | 10 | * Fixed `assert.request()` client logic into an issue() function, fired upon the `listen()` callback if the server doesn't have an assigned fd. [guillermo] 11 | * Removed `--watch` 12 | 13 | 0.7.0 / 2010-11-19 14 | ================== 15 | 16 | * Removed `assert` from test function signature 17 | Just use `require('assert')` :) this will make integration 18 | with libraries like [should](http://github.com/visionmedia/should) cleaner. 19 | 20 | 0.6.4 / 2010-11-02 21 | ================== 22 | 23 | * Added regexp support to `assert.response()` headers 24 | * Removed `waitForExit` code, causing issues 25 | 26 | 0.6.3 / 2010-11-02 27 | ================== 28 | 29 | * Added `assert.response()` body RegExp support 30 | * Fixed issue with _--serial_ not executing files sequentially. Closes #42 31 | * Fixed hang when modules use `setInterval` - monitor running tests & force the process to quit after all have completed + timeout [Steve Mason] 32 | 33 | 0.6.2 / 2010-09-17 34 | ================== 35 | 36 | * Added _node-jsocoverage_ to package.json (aka will respect npm's binroot) 37 | * Added _-t, --timeout_ MS option, defaulting to 2000 ms 38 | * Added _-s, --serial_ 39 | * __PREFIX__ clobberable 40 | * Fixed `assert.response()` for latest node 41 | * Fixed cov reporting from exploding on empty files 42 | 43 | 0.6.2 / 2010-08-03 44 | ================== 45 | 46 | * Added `assert.type()` 47 | * Renamed `assert.isNotUndefined()` to `assert.isDefined()` 48 | * Fixed `assert.includes()` param ordering 49 | 50 | 0.6.0 / 2010-07-31 51 | ================== 52 | 53 | * Added _docs/api.html_ 54 | * Added -w, --watch 55 | * Added `Array` support to `assert.includes()` 56 | * Added; outputting exceptions immediately. Closes #19 57 | * Fixed `assert.includes()` param ordering 58 | * Fixed `assert.length()` param ordering 59 | * Fixed jscoverage links 60 | 61 | 0.5.0 / 2010-07-16 62 | ================== 63 | 64 | * Added support for async exports 65 | * Added timeout support to `assert.response()`. Closes #3 66 | * Added 4th arg callback support to `assert.response()` 67 | * Added `assert.length()` 68 | * Added `assert.match()` 69 | * Added `assert.isUndefined()` 70 | * Added `assert.isNull()` 71 | * Added `assert.includes()` 72 | * Added growlnotify support via -g, --growl 73 | * Added -o, --only TESTS. Ex: --only "test foo()" --only "test foo(), test bar()" 74 | * Removed profanity 75 | 76 | 0.4.0 / 2010-07-09 77 | ================== 78 | 79 | * Added reporting source coverage (respects --boring for color haters) 80 | * Added callback to assert.response(). Closes #12 81 | * Fixed; putting exceptions to stderr. Closes #13 82 | 83 | 0.3.1 / 2010-06-28 84 | ================== 85 | 86 | * Faster assert.response() 87 | 88 | 0.3.0 / 2010-06-28 89 | ================== 90 | 91 | * Added -p, --port NUM flags 92 | * Added assert.response(). Closes #11 93 | 94 | 0.2.1 / 2010-06-25 95 | ================== 96 | 97 | * Fixed issue with reporting object assertions 98 | 99 | 0.2.0 / 2010-06-21 100 | ================== 101 | 102 | * Added `make uninstall` 103 | * Added better readdir() failure message 104 | * Fixed `make install` for kiwi 105 | 106 | 0.1.0 / 2010-06-15 107 | ================== 108 | 109 | * Added better usage docs via --help 110 | * Added better conditional color support 111 | * Added pre exit assertion support 112 | 113 | 0.0.3 / 2010-06-02 114 | ================== 115 | 116 | * Added more room for filenames in test coverage 117 | * Added boring output support via --boring (suppress colored output) 118 | * Fixed async failure exit status 119 | 120 | 0.0.2 / 2010-05-30 121 | ================== 122 | 123 | * Fixed exit status for CI support 124 | 125 | 0.0.1 / 2010-05-30 126 | ================== 127 | 128 | * Initial release -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/qs/test/querystring.test.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Module dependencies. 4 | */ 5 | 6 | var qs = require('../') 7 | , should = require('should'); 8 | 9 | module.exports = { 10 | 'test basics': function(){ 11 | qs.parse('0=foo').should.eql({ '0': 'foo' }); 12 | 13 | qs.parse('foo=c++') 14 | .should.eql({ foo: 'c ' }); 15 | 16 | qs.parse('a[>=]=23') 17 | .should.eql({ a: { '>=': '23' }}); 18 | 19 | qs.parse('a[<=>]==23') 20 | .should.eql({ a: { '<=>': '=23' }}); 21 | 22 | qs.parse('a[==]=23') 23 | .should.eql({ a: { '==': '23' }}); 24 | 25 | qs.parse('foo') 26 | .should.eql({ foo: '' }); 27 | 28 | qs.parse('foo=bar') 29 | .should.eql({ foo: 'bar' }); 30 | 31 | qs.parse('foo%3Dbar=baz') 32 | .should.eql({ foo: 'bar=baz' }); 33 | 34 | qs.parse(' foo = bar = baz ') 35 | .should.eql({ ' foo ': ' bar = baz ' }); 36 | 37 | qs.parse('foo=bar=baz') 38 | .should.eql({ foo: 'bar=baz' }); 39 | 40 | qs.parse('foo=bar&bar=baz') 41 | .should.eql({ foo: 'bar', bar: 'baz' }); 42 | 43 | qs.parse('foo=bar&baz') 44 | .should.eql({ foo: 'bar', baz: '' }); 45 | 46 | qs.parse('cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World') 47 | .should.eql({ 48 | cht: 'p3' 49 | , chd: 't:60,40' 50 | , chs: '250x100' 51 | , chl: 'Hello|World' 52 | }); 53 | }, 54 | 55 | 'test nesting': function(){ 56 | qs.parse('ops[>=]=25') 57 | .should.eql({ ops: { '>=': '25' }}); 58 | 59 | qs.parse('user[name]=tj') 60 | .should.eql({ user: { name: 'tj' }}); 61 | 62 | qs.parse('user[name][first]=tj&user[name][last]=holowaychuk') 63 | .should.eql({ user: { name: { first: 'tj', last: 'holowaychuk' }}}); 64 | }, 65 | 66 | 'test escaping': function(){ 67 | qs.parse('foo=foo%20bar') 68 | .should.eql({ foo: 'foo bar' }); 69 | }, 70 | 71 | 'test arrays': function(){ 72 | qs.parse('images[]') 73 | .should.eql({ images: [] }); 74 | 75 | qs.parse('user[]=tj') 76 | .should.eql({ user: ['tj'] }); 77 | 78 | qs.parse('user[]=tj&user[]=tobi&user[]=jane') 79 | .should.eql({ user: ['tj', 'tobi', 'jane'] }); 80 | 81 | qs.parse('user[names][]=tj&user[names][]=tyler') 82 | .should.eql({ user: { names: ['tj', 'tyler'] }}); 83 | 84 | qs.parse('user[names][]=tj&user[names][]=tyler&user[email]=tj@vision-media.ca') 85 | .should.eql({ user: { names: ['tj', 'tyler'], email: 'tj@vision-media.ca' }}); 86 | 87 | qs.parse('items=a&items=b') 88 | .should.eql({ items: ['a', 'b'] }); 89 | 90 | qs.parse('user[names]=tj&user[names]=holowaychuk&user[names]=TJ') 91 | .should.eql({ user: { names: ['tj', 'holowaychuk', 'TJ'] }}); 92 | 93 | qs.parse('user[name][first]=tj&user[name][first]=TJ') 94 | .should.eql({ user: { name: { first: ['tj', 'TJ'] }}}); 95 | }, 96 | 97 | 'test right-hand brackets': function(){ 98 | qs.parse('pets=["tobi"]') 99 | .should.eql({ pets: '["tobi"]' }); 100 | 101 | qs.parse('operators=[">=", "<="]') 102 | .should.eql({ operators: '[">=", "<="]' }); 103 | 104 | qs.parse('op[>=]=[1,2,3]') 105 | .should.eql({ op: { '>=': '[1,2,3]' }}); 106 | 107 | qs.parse('op[>=]=[1,2,3]&op[=]=[[[[1]]]]') 108 | .should.eql({ op: { '>=': '[1,2,3]', '=': '[[[[1]]]]' }}); 109 | }, 110 | 111 | 'test duplicates': function(){ 112 | qs.parse('items=bar&items=baz&items=raz') 113 | .should.eql({ items: ['bar', 'baz', 'raz'] }); 114 | }, 115 | 116 | 'test empty': function(){ 117 | qs.parse('').should.eql({}); 118 | qs.parse(undefined).should.eql({}); 119 | qs.parse(null).should.eql({}); 120 | } 121 | 122 | // 'test complex': function(){ 123 | // qs.parse('users[][name][first]=tj&users[foo]=bar') 124 | // .should.eql({ 125 | // users: [ { name: 'tj' }, { name: 'tobi' }, { foo: 'bar' }] 126 | // }); 127 | // 128 | // qs.parse('users[][name][first]=tj&users[][name][first]=tobi') 129 | // .should.eql({ 130 | // users: [ { name: 'tj' }, { name: 'tobi' }] 131 | // }); 132 | // } 133 | }; 134 | -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/connect/lib/middleware/compiler.js: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * Connect - compiler 4 | * Copyright(c) 2010 Sencha Inc. 5 | * Copyright(c) 2011 TJ Holowaychuk 6 | * MIT Licensed 7 | */ 8 | 9 | /** 10 | * Module dependencies. 11 | */ 12 | 13 | var fs = require('fs') 14 | , path = require('path') 15 | , parse = require('url').parse; 16 | 17 | /** 18 | * Require cache. 19 | */ 20 | 21 | var cache = {}; 22 | 23 | /** 24 | * Setup compiler. 25 | * 26 | * Options: 27 | * 28 | * - `src` Source directory, defaults to **CWD**. 29 | * - `dest` Destination directory, defaults `src`. 30 | * - `enable` Array of enabled compilers. 31 | * 32 | * Compilers: 33 | * 34 | * - `sass` Compiles cass to css 35 | * - `less` Compiles less to css 36 | * - `coffeescript` Compiles coffee to js 37 | * 38 | * @param {Object} options 39 | * @api public 40 | */ 41 | 42 | exports = module.exports = function compiler(options){ 43 | options = options || {}; 44 | 45 | var srcDir = options.src || process.cwd() 46 | , destDir = options.dest || srcDir 47 | , enable = options.enable; 48 | 49 | if (!enable || enable.length === 0) { 50 | throw new Error('compiler\'s "enable" option is not set, nothing will be compiled.'); 51 | } 52 | 53 | return function compiler(req, res, next){ 54 | if ('GET' != req.method) return next(); 55 | var pathname = parse(req.url).pathname; 56 | for (var i = 0, len = enable.length; i < len; ++i) { 57 | var name = enable[i] 58 | , compiler = compilers[name]; 59 | if (compiler.match.test(pathname)) { 60 | var src = (srcDir + pathname).replace(compiler.match, compiler.ext) 61 | , dest = destDir + pathname; 62 | 63 | // Compare mtimes 64 | fs.stat(src, function(err, srcStats){ 65 | if (err) { 66 | if ('ENOENT' == err.code) { 67 | next(); 68 | } else { 69 | next(err); 70 | } 71 | } else { 72 | fs.stat(dest, function(err, destStats){ 73 | if (err) { 74 | // Oh snap! it does not exist, compile it 75 | if ('ENOENT' == err.code) { 76 | compile(); 77 | } else { 78 | next(err); 79 | } 80 | } else { 81 | // Source has changed, compile it 82 | if (srcStats.mtime > destStats.mtime) { 83 | compile(); 84 | } else { 85 | // Defer file serving 86 | next(); 87 | } 88 | } 89 | }); 90 | } 91 | }); 92 | 93 | // Compile to the destination 94 | function compile() { 95 | fs.readFile(src, 'utf8', function(err, str){ 96 | if (err) { 97 | next(err); 98 | } else { 99 | compiler.compile(str, function(err, str){ 100 | if (err) { 101 | next(err); 102 | } else { 103 | fs.writeFile(dest, str, 'utf8', function(err){ 104 | next(err); 105 | }); 106 | } 107 | }); 108 | } 109 | }); 110 | } 111 | return; 112 | } 113 | } 114 | next(); 115 | }; 116 | }; 117 | 118 | /** 119 | * Bundled compilers: 120 | * 121 | * - [sass](http://github.com/visionmedia/sass.js) to _css_ 122 | * - [less](http://github.com/cloudhead/less.js) to _css_ 123 | * - [coffee](http://github.com/jashkenas/coffee-script) to _js_ 124 | */ 125 | 126 | var compilers = exports.compilers = { 127 | sass: { 128 | match: /\.css$/, 129 | ext: '.sass', 130 | compile: function(str, fn){ 131 | var sass = cache.sass || (cache.sass = require('sass')); 132 | try { 133 | fn(null, sass.render(str)); 134 | } catch (err) { 135 | fn(err); 136 | } 137 | } 138 | }, 139 | less: { 140 | match: /\.css$/, 141 | ext: '.less', 142 | compile: function(str, fn){ 143 | var less = cache.less || (cache.less = require('less')); 144 | try { 145 | less.render(str, fn); 146 | } catch (err) { 147 | fn(err); 148 | } 149 | } 150 | }, 151 | coffeescript: { 152 | match: /\.js$/, 153 | ext: '.coffee', 154 | compile: function(str, fn){ 155 | var coffee = cache.coffee || (cache.coffee = require('coffee-script')); 156 | try { 157 | fn(null, coffee.compile(str)); 158 | } catch (err) { 159 | fn(err); 160 | } 161 | } 162 | } 163 | }; -------------------------------------------------------------------------------- /test/node_modules/express/lib/view/view.js: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * Express - View 4 | * Copyright(c) 2010 TJ Holowaychuk 5 | * MIT Licensed 6 | */ 7 | 8 | /** 9 | * Module dependencies. 10 | */ 11 | 12 | var path = require('path') 13 | , extname = path.extname 14 | , dirname = path.dirname 15 | , basename = path.basename 16 | , fs = require('fs') 17 | , stat = fs.statSync; 18 | 19 | /** 20 | * Expose `View`. 21 | */ 22 | 23 | exports = module.exports = View; 24 | 25 | /** 26 | * Require cache. 27 | */ 28 | 29 | var cache = {}; 30 | 31 | /** 32 | * Initialize a new `View` with the given `view` path and `options`. 33 | * 34 | * @param {String} view 35 | * @param {Object} options 36 | * @api private 37 | */ 38 | 39 | function View(view, options) { 40 | options = options || {}; 41 | this.view = view; 42 | this.root = options.root; 43 | this.relative = false !== options.relative; 44 | this.defaultEngine = options.defaultEngine; 45 | this.parent = options.parentView; 46 | this.basename = basename(view); 47 | this.engine = this.resolveEngine(); 48 | this.extension = '.' + this.engine; 49 | this.name = this.basename.replace(this.extension, ''); 50 | this.path = this.resolvePath(); 51 | this.dirname = dirname(this.path); 52 | if (options.attempts) options.attempts.push(this.path); 53 | }; 54 | 55 | /** 56 | * Check if the view path exists. 57 | * 58 | * @return {Boolean} 59 | * @api public 60 | */ 61 | 62 | View.prototype.__defineGetter__('exists', function(){ 63 | try { 64 | stat(this.path); 65 | return true; 66 | } catch (err) { 67 | return false; 68 | } 69 | }); 70 | 71 | /** 72 | * Resolve view engine. 73 | * 74 | * @return {String} 75 | * @api private 76 | */ 77 | 78 | View.prototype.resolveEngine = function(){ 79 | // Explicit 80 | if (~this.basename.indexOf('.')) return extname(this.basename).substr(1); 81 | // Inherit from parent 82 | if (this.parent) return this.parent.engine; 83 | // Default 84 | return this.defaultEngine; 85 | }; 86 | 87 | /** 88 | * Resolve view path. 89 | * 90 | * @return {String} 91 | * @api private 92 | */ 93 | 94 | View.prototype.resolvePath = function(){ 95 | var path = this.view; 96 | // Implicit engine 97 | if (!~this.basename.indexOf('.')) path += this.extension; 98 | // Absolute 99 | if ('/' == path[0]) return path; 100 | // Relative to parent 101 | if (this.relative && this.parent) return this.parent.dirname + '/' + path; 102 | // Relative to root 103 | return this.root 104 | ? this.root + '/' + path 105 | : path; 106 | }; 107 | 108 | /** 109 | * Get view contents. This is a one-time hit, so we 110 | * can afford to be sync. 111 | * 112 | * @return {String} 113 | * @api public 114 | */ 115 | 116 | View.prototype.__defineGetter__('contents', function(){ 117 | return fs.readFileSync(this.path, 'utf8'); 118 | }); 119 | 120 | /** 121 | * Get template engine api, cache exports to reduce 122 | * require() calls. 123 | * 124 | * @return {Object} 125 | * @api public 126 | */ 127 | 128 | View.prototype.__defineGetter__('templateEngine', function(){ 129 | var ext = this.extension; 130 | return cache[ext] || (cache[ext] = require(this.engine)); 131 | }); 132 | 133 | /** 134 | * Return root path alternative. 135 | * 136 | * @return {String} 137 | * @api public 138 | */ 139 | 140 | View.prototype.__defineGetter__('rootPath', function(){ 141 | this.relative = false; 142 | return this.resolvePath(); 143 | }); 144 | 145 | /** 146 | * Return index path alternative. 147 | * 148 | * @return {String} 149 | * @api public 150 | */ 151 | 152 | View.prototype.__defineGetter__('indexPath', function(){ 153 | return this.dirname 154 | + '/' + this.basename.replace(this.extension, '') 155 | + '/index' + this.extension; 156 | }); 157 | 158 | /** 159 | * Return ..//index path alternative. 160 | * 161 | * @return {String} 162 | * @api public 163 | */ 164 | 165 | View.prototype.__defineGetter__('upIndexPath', function(){ 166 | return this.dirname + '/../' + this.name + '/index' + this.extension; 167 | }); 168 | 169 | /** 170 | * Return _ prefix path alternative 171 | * 172 | * @return {String} 173 | * @api public 174 | */ 175 | 176 | View.prototype.__defineGetter__('prefixPath', function(){ 177 | return this.dirname + '/_' + this.basename; 178 | }); 179 | 180 | /** 181 | * Register the given template engine `exports` 182 | * as `ext`. For example we may wish to map ".html" 183 | * files to jade: 184 | * 185 | * app.register('.html', require('jade')); 186 | * 187 | * or 188 | * 189 | * app.register('html', require('jade')); 190 | * 191 | * This is also useful for libraries that may not 192 | * match extensions correctly. For example my haml.js 193 | * library is installed from npm as "hamljs" so instead 194 | * of layout.hamljs, we can register the engine as ".haml": 195 | * 196 | * app.register('.haml', require('haml-js')); 197 | * 198 | * @param {String} ext 199 | * @param {Object} obj 200 | * @api public 201 | */ 202 | 203 | exports.register = function(ext, exports) { 204 | if ('.' != ext[0]) ext = '.' + ext; 205 | cache[ext] = exports; 206 | }; 207 | -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/connect/lib/middleware/logger.js: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * Connect - logger 4 | * Copyright(c) 2010 Sencha Inc. 5 | * Copyright(c) 2011 TJ Holowaychuk 6 | * MIT Licensed 7 | */ 8 | 9 | /** 10 | * Log buffer. 11 | */ 12 | 13 | var buf = []; 14 | 15 | /** 16 | * Default log buffer duration. 17 | */ 18 | 19 | var defaultBufferDuration = 1000; 20 | 21 | /** 22 | * Log requests with the given `options` or a `format` string. 23 | * 24 | * Options: 25 | * 26 | * - `format` Format string, see below for tokens 27 | * - `stream` Output stream, defaults to _stdout_ 28 | * - `buffer` Buffer duration, defaults to 1000ms when _true_ 29 | * 30 | * Tokens: 31 | * 32 | * - `:req[header]` ex: `:req[Accept]` 33 | * - `:res[header]` ex: `:res[Content-Length]` 34 | * - `:http-version` 35 | * - `:response-time` 36 | * - `:remote-addr` 37 | * - `:date` 38 | * - `:method` 39 | * - `:url` 40 | * - `:referrer` 41 | * - `:user-agent` 42 | * - `:status` 43 | * 44 | * @param {String|Function|Object} format or options 45 | * @return {Function} 46 | * @api public 47 | */ 48 | 49 | module.exports = function logger(options) { 50 | if ('object' == typeof options) { 51 | options = options || {}; 52 | } else if (options) { 53 | options = { format: options }; 54 | } else { 55 | options = {}; 56 | } 57 | 58 | var fmt = options.format 59 | , stream = options.stream || process.stdout 60 | , buffer = options.buffer; 61 | 62 | // buffering support 63 | if (buffer) { 64 | var realStream = stream 65 | , interval = 'number' == typeof buffer 66 | ? buffer 67 | : defaultBufferDuration; 68 | 69 | // flush interval 70 | setInterval(function(){ 71 | if (buf.length) { 72 | realStream.write(buf.join(''), 'ascii'); 73 | buf.length = 0; 74 | } 75 | }, interval); 76 | 77 | // swap the stream 78 | stream = { 79 | write: function(str){ 80 | buf.push(str); 81 | } 82 | }; 83 | } 84 | 85 | return function logger(req, res, next) { 86 | var start = +new Date 87 | , statusCode 88 | , writeHead = res.writeHead 89 | , end = res.end 90 | , url = req.originalUrl; 91 | 92 | // mount safety 93 | if (req._logging) return next(); 94 | 95 | // flag as logging 96 | req._logging = true; 97 | 98 | // proxy for statusCode. 99 | res.writeHead = function(code, headers){ 100 | res.writeHead = writeHead; 101 | res.writeHead(code, headers); 102 | res.__statusCode = statusCode = code; 103 | res.__headers = headers || {}; 104 | }; 105 | 106 | // proxy end to output a line to the provided logger. 107 | if (fmt) { 108 | res.end = function(chunk, encoding) { 109 | res.end = end; 110 | res.end(chunk, encoding); 111 | res.responseTime = +new Date - start; 112 | if ('function' == typeof fmt) { 113 | var line = fmt(req, res, function(str){ return format(str, req, res); }); 114 | if (line) stream.write(line + '\n', 'ascii'); 115 | } else { 116 | stream.write(format(fmt, req, res) + '\n', 'ascii'); 117 | } 118 | }; 119 | } else { 120 | res.end = function(chunk, encoding) { 121 | var contentLength = (res._headers && res._headers['content-length']) 122 | || (res.__headers && res.__headers['Content-Length']) 123 | || '-'; 124 | 125 | res.end = end; 126 | res.end(chunk, encoding); 127 | 128 | stream.write((req.socket && (req.socket.remoteAddress || (req.socket.socket && req.socket.socket.remoteAddress))) 129 | + ' - - [' + (new Date).toUTCString() + ']' 130 | + ' "' + req.method + ' ' + url 131 | + ' HTTP/' + req.httpVersionMajor + '.' + req.httpVersionMinor + '" ' 132 | + (statusCode || res.statusCode) + ' ' + contentLength 133 | + ' "' + (req.headers['referer'] || req.headers['referrer'] || '') 134 | + '" "' + (req.headers['user-agent'] || '') + '"\n', 'ascii'); 135 | }; 136 | } 137 | 138 | next(); 139 | }; 140 | }; 141 | 142 | /** 143 | * Return formatted log line. 144 | * 145 | * @param {String} str 146 | * @param {IncomingMessage} req 147 | * @param {ServerResponse} res 148 | * @return {String} 149 | * @api private 150 | */ 151 | 152 | function format(str, req, res) { 153 | return str 154 | .replace(':url', req.originalUrl) 155 | .replace(':method', req.method) 156 | .replace(':status', res.__statusCode || res.statusCode) 157 | .replace(':response-time', res.responseTime) 158 | .replace(':date', new Date().toUTCString()) 159 | .replace(':referrer', req.headers['referer'] || req.headers['referrer'] || '') 160 | .replace(':http-version', req.httpVersionMajor + '.' + req.httpVersionMinor) 161 | .replace(':remote-addr', req.socket && (req.socket.remoteAddress || (req.socket.socket && req.socket.socket.remoteAddress))) 162 | .replace(':user-agent', req.headers['user-agent'] || '') 163 | .replace(/:req\[([^\]]+)\]/g, function(_, field){ return req.headers[field.toLowerCase()]; }) 164 | .replace(/:res\[([^\]]+)\]/g, function(_, field){ 165 | return res._headers 166 | ? (res._headers[field.toLowerCase()] || res.__headers[field]) 167 | : (res.__headers && res.__headers[field]); 168 | }); 169 | } 170 | -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/connect/lib/middleware/static.js: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * Connect - staticProvider 4 | * Copyright(c) 2010 Sencha Inc. 5 | * Copyright(c) 2011 TJ Holowaychuk 6 | * MIT Licensed 7 | */ 8 | 9 | /** 10 | * Module dependencies. 11 | */ 12 | 13 | var fs = require('fs') 14 | , join = require('path').join 15 | , utils = require('../utils') 16 | , Buffer = require('buffer').Buffer 17 | , parse = require('url').parse 18 | , mime = require('mime'); 19 | 20 | /** 21 | * Static file server with the given `root` path. 22 | * 23 | * Examples: 24 | * 25 | * var oneDay = 86400000; 26 | * 27 | * connect( 28 | * connect.static(__dirname + '/public') 29 | * ).listen(3000); 30 | * 31 | * connect( 32 | * connect.static(__dirname + '/public', { maxAge: oneDay }) 33 | * ).listen(3000); 34 | * 35 | * Options: 36 | * 37 | * - `maxAge` Browser cache maxAge in milliseconds, defaults to 0 38 | * 39 | * @param {String} root 40 | * @param {Object} options 41 | * @return {Function} 42 | * @api public 43 | */ 44 | 45 | exports = module.exports = function static(root, options){ 46 | options = options || {}; 47 | 48 | // root required 49 | if (!root) throw new Error('static() root path required'); 50 | options.root = root; 51 | 52 | return function static(req, res, next) { 53 | options.path = req.url; 54 | send(req, res, next, options); 55 | }; 56 | }; 57 | 58 | /** 59 | * Respond with 403 "Forbidden". 60 | * 61 | * @param {ServerResponse} res 62 | * @api private 63 | */ 64 | 65 | function forbidden(res) { 66 | var body = 'Forbidden'; 67 | res.setHeader('Content-Type', 'text/plain'); 68 | res.setHeader('Content-Length', body.length); 69 | res.statusCode = 403; 70 | res.end(body); 71 | } 72 | 73 | /** 74 | * Respond with 416 "Requested Range Not Satisfiable" 75 | * 76 | * @param {ServerResponse} res 77 | * @api private 78 | */ 79 | 80 | function invalidRange(res) { 81 | var body = 'Requested Range Not Satisfiable'; 82 | res.setHeader('Content-Type', 'text/plain'); 83 | res.setHeader('Content-Length', body.length); 84 | res.statusCode = 416; 85 | res.end(body); 86 | } 87 | 88 | /** 89 | * Attempt to tranfer the requseted file to `res`. 90 | * 91 | * @param {ServerRequest} 92 | * @param {ServerResponse} 93 | * @param {Function} next 94 | * @param {Object} options 95 | * @api private 96 | */ 97 | 98 | var send = exports.send = function(req, res, next, options){ 99 | options = options || {}; 100 | if (!options.path) throw new Error('path required'); 101 | 102 | // setup 103 | var maxAge = options.maxAge || 0 104 | , ranges = req.headers.range 105 | , head = 'HEAD' == req.method 106 | , root = options.root 107 | , fn = options.callback; 108 | 109 | // replace next() with callback when available 110 | if (fn) next = fn; 111 | 112 | // ignore non-GET requests 113 | if ('GET' != req.method && !head) return next(); 114 | 115 | // parse url 116 | var url = parse(options.path) 117 | , path = decodeURIComponent(url.pathname) 118 | , type; 119 | 120 | // potentially malicious path 121 | if (~path.indexOf('..')) return fn 122 | ? fn(new Error('Forbidden')) 123 | : forbidden(res); 124 | 125 | // join from optional root dir 126 | path = join(options.root, path); 127 | 128 | // index.html support 129 | if ('/' == path[path.length - 1]) path += 'index.html'; 130 | 131 | // mime type 132 | type = mime.lookup(path); 133 | 134 | fs.stat(path, function(err, stat){ 135 | // ignore ENOENT 136 | if (err) { 137 | if (fn) return fn(err); 138 | return 'ENOENT' == err.code 139 | ? next() 140 | : next(err); 141 | // ignore directories 142 | } else if (stat.isDirectory()) { 143 | return fn 144 | ? fn(new Error('Cannot Transfer Directory')) 145 | : next(); 146 | } 147 | 148 | // we have a Range request 149 | if (ranges) { 150 | ranges = utils.parseRange(stat.size, ranges); 151 | // valid 152 | if (ranges) { 153 | // TODO: stream options 154 | // TODO: multiple support 155 | var stream = fs.createReadStream(path, ranges[0]) 156 | , start = ranges[0].start 157 | , end = ranges[0].end; 158 | res.statusCode = 206; 159 | res.setHeader('Content-Range', 'bytes ' 160 | + start 161 | + '-' 162 | + end 163 | + '/' 164 | + stat.size); 165 | // invalid 166 | } else { 167 | return fn 168 | ? fn(new Error('Requested Range Not Satisfiable')) 169 | : invalidRange(res); 170 | } 171 | // stream the entire file 172 | } else { 173 | res.setHeader('Content-Length', stat.size); 174 | res.setHeader('Cache-Control', 'public, max-age=' + (maxAge / 1000)); 175 | res.setHeader('Last-Modified', stat.mtime.toUTCString()); 176 | res.setHeader('ETag', utils.etag(stat)); 177 | 178 | // conditional GET support 179 | if (utils.conditionalGET(req)) { 180 | if (!utils.modified(req, res)) { 181 | return utils.notModified(res); 182 | } 183 | } 184 | 185 | // read stream 186 | var stream = fs.createReadStream(path); 187 | } 188 | 189 | // transfer 190 | if (!res.getHeader('content-type')) { 191 | var charset = mime.charsets.lookup(type); 192 | res.setHeader('Content-Type', type + (charset ? '; charset=' + charset : '')); 193 | } 194 | res.setHeader('Accept-Ranges', 'bytes'); 195 | 196 | if (head) return res.end(); 197 | stream.pipe(res); 198 | if (fn) { 199 | res.connection.on('error', fn); 200 | stream.on('end', fn); 201 | } 202 | }); 203 | }; -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/connect/lib/http.js: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * Connect - HTTPServer 4 | * Copyright(c) 2010 Sencha Inc. 5 | * Copyright(c) 2011 TJ Holowaychuk 6 | * MIT Licensed 7 | */ 8 | 9 | /** 10 | * Module dependencies. 11 | */ 12 | 13 | var http = require('http') 14 | , parse = require('url').parse 15 | , assert = require('assert'); 16 | 17 | // environment 18 | 19 | var env = process.env.NODE_ENV || 'development'; 20 | 21 | /** 22 | * Initialize a new `Server` with the given `middleware`. 23 | * 24 | * Examples: 25 | * 26 | * var server = connect.createServer( 27 | * connect.favicon() 28 | * , connect.logger() 29 | * , connect.static(__dirname + '/public') 30 | * ); 31 | * 32 | * @params {Array} middleware 33 | * @return {Server} 34 | * @api public 35 | */ 36 | 37 | var Server = exports.Server = function HTTPServer(middleware) { 38 | this.stack = []; 39 | middleware.forEach(function(fn){ 40 | this.use(fn); 41 | }, this); 42 | http.Server.call(this, this.handle); 43 | }; 44 | 45 | /** 46 | * Inherit from `http.Server.prototype`. 47 | */ 48 | 49 | Server.prototype.__proto__ = http.Server.prototype; 50 | 51 | /** 52 | * Utilize the given middleware `handle` to the given `route`, 53 | * defaulting to _/_. This "route" is the mount-point for the 54 | * middleware, when given a value other than _/_ the middleware 55 | * is only effective when that segment is present in the request's 56 | * pathname. 57 | * 58 | * For example if we were to mount a function at _/admin_, it would 59 | * be invoked on _/admin_, and _/admin/settings_, however it would 60 | * not be invoked for _/_, or _/posts_. 61 | * 62 | * This is effectively the same as passing middleware to `connect.createServer()`, 63 | * however provides a progressive api. 64 | * 65 | * Examples: 66 | * 67 | * var server = connect.createServer(); 68 | * server.use(connect.favicon()); 69 | * server.use(connect.logger()); 70 | * server.use(connect.static(__dirname + '/public')); 71 | * 72 | * If we wanted to prefix static files with _/public_, we could 73 | * "mount" the `static()` middleware: 74 | * 75 | * server.use('/public', connect.static(__dirname + '/public')); 76 | * 77 | * This api is chainable, meaning the following is valid: 78 | * 79 | * connect.createServer() 80 | * .use(connect.favicon()) 81 | * .use(connect.logger()) 82 | * .use(connect.static(__dirname + '/public')) 83 | * .listen(3000); 84 | * 85 | * @param {String|Function} route or handle 86 | * @param {Function} handle 87 | * @return {Server} 88 | * @api public 89 | */ 90 | 91 | Server.prototype.use = function(route, handle){ 92 | this.route = '/'; 93 | 94 | // default route to '/' 95 | if ('string' != typeof route) { 96 | handle = route; 97 | route = '/'; 98 | } 99 | 100 | // multiples 101 | if (arguments.length > 2) { 102 | return Array.prototype.slice.call(arguments, 1).forEach(function(fn){ 103 | this.use(route, fn); 104 | }, this); 105 | } 106 | 107 | // wrap sub-apps 108 | if ('function' == typeof handle.handle) { 109 | var server = handle; 110 | server.route = route; 111 | handle = function(req, res, next) { 112 | server.handle(req, res, next); 113 | }; 114 | } 115 | 116 | // wrap vanilla http.Servers 117 | if (handle instanceof http.Server) { 118 | handle = handle.listeners('request')[0]; 119 | } 120 | 121 | // normalize route to not trail with slash 122 | if ('/' == route[route.length - 1]) { 123 | route = route.substr(0, route.length - 1); 124 | } 125 | 126 | // add the middleware 127 | this.stack.push({ route: route, handle: handle }); 128 | 129 | // allow chaining 130 | return this; 131 | }; 132 | 133 | /** 134 | * Handle server requests, punting them down 135 | * the middleware stack. 136 | * 137 | * @api private 138 | */ 139 | 140 | Server.prototype.handle = function(req, res, out) { 141 | var writeHead = res.writeHead 142 | , stack = this.stack 143 | , removed = '' 144 | , index = 0; 145 | 146 | function next(err) { 147 | req.url = removed + req.url; 148 | req.originalUrl = req.originalUrl || req.url; 149 | removed = ''; 150 | 151 | var layer = stack[index++]; 152 | 153 | // all done 154 | if (!layer) { 155 | // but wait! we have a parent 156 | if (out) return out(err); 157 | 158 | // otherwise send a proper error message to the browser. 159 | if (err) { 160 | var msg = 'production' == env 161 | ? 'Internal Server Error' 162 | : err.stack || err.toString(); 163 | 164 | // output to stderr in a non-test env 165 | if ('test' != env) console.error(err.stack || err.toString()); 166 | 167 | res.statusCode = 500; 168 | res.setHeader('Content-Type', 'text/plain'); 169 | res.end(msg); 170 | } else { 171 | res.statusCode = 404; 172 | res.setHeader('Content-Type', 'text/plain'); 173 | res.end('Cannot ' + req.method + ' ' + req.url); 174 | } 175 | return; 176 | } 177 | 178 | try { 179 | var pathname = parse(req.url).pathname; 180 | if (undefined == pathname) pathname = '/'; 181 | 182 | // skip this layer if the route doesn't match. 183 | if (0 != pathname.indexOf(layer.route)) return next(err); 184 | 185 | var nextChar = pathname[layer.route.length]; 186 | if (nextChar && '/' != nextChar && '.' != nextChar) return next(err); 187 | 188 | // Call the layer handler 189 | // Trim off the part of the url that matches the route 190 | removed = layer.route; 191 | req.url = req.url.substr(removed.length); 192 | 193 | // Ensure leading slash 194 | if ('/' != req.url[0]) req.url = '/' + req.url; 195 | 196 | var arity = layer.handle.length; 197 | if (err) { 198 | if (arity === 4) { 199 | layer.handle(err, req, res, next); 200 | } else { 201 | next(err); 202 | } 203 | } else if (arity < 4) { 204 | layer.handle(req, res, next); 205 | } else { 206 | next(); 207 | } 208 | } catch (e) { 209 | if (e instanceof assert.AssertionError) { 210 | console.error(e.stack + '\n'); 211 | next(e); 212 | } else { 213 | next(e); 214 | } 215 | } 216 | } 217 | next(); 218 | }; -------------------------------------------------------------------------------- /test/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | LazyLoad Test 5 | 25 | 26 | 27 |

    LazyLoad Test

    28 | 29 |
    30 |
    31 | JavaScript 32 | 33 |

    34 | 35 | 36 | 37 |

    38 | 39 |

    40 | 41 |

    42 |
    43 | 44 |
    45 | CSS 46 | 47 |

    48 | 49 | 50 | 51 |

    52 | 53 |

    54 | 55 |

    56 | 57 |
    58 | 59 |
    60 |
    61 |
    62 |
    63 |
    64 |
    65 |
    66 | 67 | 68 | 204 | 205 | 206 | -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/qs/support/should/Readme.md: -------------------------------------------------------------------------------- 1 | _should_ is an expressive, test framework agnostic, assertion library for [node](http://nodejs.org). 2 | 3 | _should_ literally extends node's _assert_ module, in fact, it is node's assert module, for example `should.equal(str, 'foo')` will work, just as `assert.equal(str, 'foo')` would, and `should.AssertionError` **is** `asset.AssertionError`, meaning any test framework supporting this constructor will function properly with _should_. 4 | 5 | ## Example 6 | 7 | var user = { 8 | name: 'tj' 9 | , pets: ['tobi', 'loki', 'jane', 'bandit'] 10 | }; 11 | 12 | user.should.have.property('name', 'tj'); 13 | user.should.have.property('pets').with.lengthOf(4) 14 | 15 | ## Installation 16 | 17 | $ npm install should 18 | 19 | ## modifiers 20 | 21 | _should_'s assertion chaining provides an expressive way to build up an assertion, along with dummy getters such as _an_, _have_, and _be_, provided are what I am simply calling **modifiers**, which have a meaning effect on the assertion. An example of this is the _not_ getter, which negates the meaning, aka `user.should.not.have.property('name')`. In the previous example note the use of _have_, as we could omit it and still construct a valid assertion. 22 | 23 | Some modifiers such as _include_ only have an effect with specific assertion methods, for example when asserting a substring like so: `str.should.include.string('test')`, we could omit _include_, but it helps express the meaning, however _keys_ has a strict effect, unless the _include_ modifier is used. 24 | 25 | ## chaining assertions 26 | 27 | Some assertions can be chained, for example if a property is volatile we can first assert property existence: 28 | 29 | user.should.have.property('pets').with.lengthOf(4) 30 | 31 | which is essentially equivalent to below, however the property may not exist: 32 | 33 | user.pets.should.have.lengthOf(4) 34 | 35 | our dummy getters such as _and_ also help express chaining: 36 | 37 | user.should.be.a('object').and.have.property('name', 'tj') 38 | 39 | ## ok 40 | 41 | Assert truthfulness: 42 | 43 | true.should.be.ok 44 | 'yay'.should.be.ok 45 | (1).should.be.ok 46 | 47 | or negated: 48 | 49 | false.should.not.be.ok 50 | ''.should.not.be.ok 51 | (0).should.not.be.ok 52 | 53 | ## true 54 | 55 | Assert === true: 56 | 57 | true.should.be.true 58 | '1'.should.not.be.true 59 | 60 | ## false 61 | 62 | Assert === false: 63 | 64 | false.should.be.false 65 | (0).should.not.be.false 66 | 67 | ## arguments 68 | 69 | Assert `Arguments`: 70 | 71 | var args = (function(){ return arguments; })(1,2,3); 72 | args.should.be.arguments; 73 | [].should.not.be.arguments; 74 | 75 | ## empty 76 | 77 | Asserts that length is 0: 78 | 79 | [].should.be.empty 80 | ''.should.be.empty 81 | ({ length: 0 }).should.be.empty 82 | 83 | ## eql 84 | 85 | equality: 86 | 87 | ({ foo: 'bar' }).should.eql({ foo: 'bar' }) 88 | [1,2,3].should.eql([1,2,3]) 89 | 90 | ## equal 91 | 92 | strict equality: 93 | 94 | should.strictEqual(undefined, value) 95 | should.strictEqual(false, value) 96 | (4).should.equal(4) 97 | 'test'.should.equal('test') 98 | [1,2,3].should.not.equal([1,2,3]) 99 | 100 | ## within 101 | 102 | Assert inclusive numeric range: 103 | 104 | user.age.should.be.within(5, 50) 105 | 106 | ## a 107 | 108 | Assert __typeof__: 109 | 110 | user.should.be.a('object') 111 | 'test'.should.be.a('string') 112 | 113 | ## instanceof 114 | 115 | Assert __instanceof__: 116 | 117 | user.should.be.an.instanceof(User) 118 | [].should.be.an.instanceof(Array) 119 | 120 | ## above 121 | 122 | Assert numeric value above the given value: 123 | 124 | user.age.should.be.above(5) 125 | user.age.should.not.be.above(100) 126 | 127 | ## below 128 | 129 | Assert numeric value below the given value: 130 | 131 | user.age.should.be.below(100) 132 | user.age.should.not.be.below(5) 133 | 134 | ## match 135 | 136 | Assert regexp match: 137 | 138 | username.should.match(/^\w+$/) 139 | 140 | ## length 141 | 142 | Assert _length_ property exists and has a value of the given number: 143 | 144 | user.pets.should.have.length(5) 145 | user.pets.should.have.a.lengthOf(5) 146 | 147 | Aliases: _lengthOf_ 148 | 149 | ## string 150 | 151 | Substring assertion: 152 | 153 | 'foobar'.should.include.string('foo') 154 | 'foobar'.should.include.string('bar') 155 | 'foobar'.should.not.include.string('baz') 156 | 157 | ## property 158 | 159 | Assert property exists and has optional value: 160 | 161 | user.should.have.property('name') 162 | user.should.have.property('age', 15) 163 | user.should.not.have.property('rawr') 164 | user.should.not.have.property('age', 0) 165 | 166 | ## ownProperty 167 | 168 | Assert own property (on the immediate object): 169 | 170 | ({ foo: 'bar' }).should.have.ownProperty('foo') 171 | 172 | ## contain 173 | 174 | Assert array value: 175 | 176 | [1,2,3].should.contain(3) 177 | [1,2,3].should.contain(2) 178 | [1,2,3].should.not.contain(4) 179 | 180 | ## keys 181 | 182 | Assert own object keys, which must match _exactly_, 183 | and will fail if you omit a key or two: 184 | 185 | var obj = { foo: 'bar', baz: 'raz' }; 186 | obj.should.have.keys('foo', 'bar'); 187 | obj.should.have.keys(['foo', 'bar']); 188 | 189 | using the _include_ modifier, we can check inclusion of a key, 190 | but not fail when we omit a few: 191 | 192 | obj.should.include.keys('foo') 193 | obj.should.include.keys('bar') 194 | obj.should.not.include.keys('baz') 195 | 196 | ## respondTo 197 | 198 | Assert that the given property is a function: 199 | 200 | user.should.respondTo('email') 201 | 202 | ## Express example 203 | 204 | For example you can use should with the [Expresso TDD Framework](http://github.com/visionmedia/expresso) by simply including it: 205 | 206 | var lib = require('mylib') 207 | , should = require('should'); 208 | 209 | module.exports = { 210 | 'test .version': function(){ 211 | lib.version.should.match(/^\d+\.\d+\.\d+$/); 212 | } 213 | }; 214 | 215 | ## Running tests 216 | 217 | To run the tests for _should_ simple update your git submodules and run: 218 | 219 | $ make test 220 | 221 | ## OMG IT EXTENDS OBJECT???!?!@ 222 | 223 | Yes, yes it does, with a single getter _should_, and no it wont break your code, because it does this **properly** with a non-enumerable property. 224 | 225 | ## License 226 | 227 | (The MIT License) 228 | 229 | Copyright (c) 2010 TJ Holowaychuk <tj@vision-media.ca> 230 | 231 | Permission is hereby granted, free of charge, to any person obtaining 232 | a copy of this software and associated documentation files (the 233 | 'Software'), to deal in the Software without restriction, including 234 | without limitation the rights to use, copy, modify, merge, publish, 235 | distribute, sublicense, and/or sell copies of the Software, and to 236 | permit persons to whom the Software is furnished to do so, subject to 237 | the following conditions: 238 | 239 | The above copyright notice and this permission notice shall be 240 | included in all copies or substantial portions of the Software. 241 | 242 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 243 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 244 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 245 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 246 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 247 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 248 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /test/node_modules/express/lib/request.js: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * Express - request 4 | * Copyright(c) 2010 TJ Holowaychuk 5 | * MIT Licensed 6 | */ 7 | 8 | /** 9 | * Module dependencies. 10 | */ 11 | 12 | var http = require('http') 13 | , req = http.IncomingMessage.prototype 14 | , utils = require('./utils') 15 | , mime = require('mime'); 16 | 17 | /** 18 | * Default flash formatters. 19 | * 20 | * @type Object 21 | */ 22 | 23 | var flashFormatters = exports.flashFormatters = { 24 | s: function(val){ 25 | return String(val); 26 | } 27 | }; 28 | 29 | /** 30 | * Return request header or optional default. 31 | * 32 | * The `Referrer` header field is special-cased, 33 | * both `Referrer` and `Referer` will yield are 34 | * interchangeable. 35 | * 36 | * Examples: 37 | * 38 | * req.header('Content-Type'); 39 | * // => "text/plain" 40 | * 41 | * req.header('content-type'); 42 | * // => "text/plain" 43 | * 44 | * req.header('Accept'); 45 | * // => undefined 46 | * 47 | * req.header('Accept', 'text/html'); 48 | * // => "text/html" 49 | * 50 | * @param {String} name 51 | * @param {String} defaultValue 52 | * @return {String} 53 | * @api public 54 | */ 55 | 56 | req.header = function(name, defaultValue){ 57 | switch (name = name.toLowerCase()) { 58 | case 'referer': 59 | case 'referrer': 60 | return this.headers.referrer 61 | || this.headers.referer 62 | || defaultValue; 63 | default: 64 | return this.headers[name] || defaultValue; 65 | } 66 | }; 67 | 68 | /** 69 | * Check if the _Accept_ header is present, and includes the given `type`. 70 | * 71 | * When the _Accept_ header is not present `true` is returned. Otherwise 72 | * the given `type` is matched by an exact match, and then subtypes. You 73 | * may pass the subtype such as "html" which is then converted internally 74 | * to "text/html" using the mime lookup table. 75 | * 76 | * Examples: 77 | * 78 | * // Accept: text/html 79 | * req.accepts('html'); 80 | * // => true 81 | * 82 | * // Accept: text/*; application/json 83 | * req.accepts('html'); 84 | * req.accepts('text/html'); 85 | * req.accepts('text/plain'); 86 | * req.accepts('application/json'); 87 | * // => true 88 | * 89 | * req.accepts('image/png'); 90 | * req.accepts('png'); 91 | * // => false 92 | * 93 | * @param {String} type 94 | * @return {Boolean} 95 | * @api public 96 | */ 97 | 98 | req.accepts = function(type){ 99 | var accept = this.header('Accept'); 100 | 101 | // normalize extensions ".json" -> "json" 102 | if (type && '.' == type[0]) type = type.substr(1); 103 | 104 | // when Accept does not exist, or is '*/*' return true 105 | if (!accept || '*/*' == accept) { 106 | return true; 107 | } else if (type) { 108 | // allow "html" vs "text/html" etc 109 | if (type.indexOf('/') < 0) { 110 | type = mime.lookup(type); 111 | } 112 | 113 | // check if we have a direct match 114 | if (~accept.indexOf(type)) return true; 115 | 116 | // check if we have type/* 117 | type = type.split('/')[0] + '/*'; 118 | return accept.indexOf(type) >= 0; 119 | } else { 120 | return false; 121 | } 122 | }; 123 | 124 | /** 125 | * Return the value of param `name` when present or `defaultValue`. 126 | * 127 | * - Checks route placeholders, ex: _/user/:id_ 128 | * - Checks query string params, ex: ?id=12 129 | * - Checks urlencoded body params, ex: id=12 130 | * 131 | * To utilize urlencoded request bodies, `req.body` 132 | * should be an object. This can be done by using 133 | * the `connect.bodyParser` middleware. 134 | * 135 | * @param {String} name 136 | * @param {Mixed} defaultValue 137 | * @return {String} 138 | * @api public 139 | */ 140 | 141 | req.param = function(name, defaultValue){ 142 | // route params like /user/:id 143 | if (this.params && this.params.hasOwnProperty(name) && undefined !== this.params[name]) { 144 | return this.params[name]; 145 | } 146 | // query string params 147 | if (undefined !== this.query[name]) { 148 | return this.query[name]; 149 | } 150 | // request body params via connect.bodyParser 151 | if (this.body && undefined !== this.body[name]) { 152 | return this.body[name]; 153 | } 154 | return defaultValue; 155 | }; 156 | 157 | /** 158 | * Queue flash `msg` of the given `type`. 159 | * 160 | * Examples: 161 | * 162 | * req.flash('info', 'email sent'); 163 | * req.flash('error', 'email delivery failed'); 164 | * req.flash('info', 'email re-sent'); 165 | * // => 2 166 | * 167 | * req.flash('info'); 168 | * // => ['email sent', 'email re-sent'] 169 | * 170 | * req.flash('info'); 171 | * // => [] 172 | * 173 | * req.flash(); 174 | * // => { error: ['email delivery failed'], info: [] } 175 | * 176 | * Formatting: 177 | * 178 | * Flash notifications also support arbitrary formatting support. 179 | * For example you may pass variable arguments to `req.flash()` 180 | * and use the %s specifier to be replaced by the associated argument: 181 | * 182 | * req.flash('info', 'email has been sent to %s.', userName); 183 | * 184 | * To add custom formatters use the `exports.flashFormatters` object. 185 | * 186 | * @param {String} type 187 | * @param {String} msg 188 | * @return {Array|Object|Number} 189 | * @api public 190 | */ 191 | 192 | req.flash = function(type, msg){ 193 | if (this.session === undefined) throw Error('req.flash() requires sessions'); 194 | var msgs = this.session.flash = this.session.flash || {}; 195 | if (type && msg) { 196 | var i = 2 197 | , args = arguments 198 | , formatters = this.app.flashFormatters || {}; 199 | formatters.__proto__ = flashFormatters; 200 | msg = utils.miniMarkdown(utils.escape(msg)); 201 | msg = msg.replace(/%([a-zA-Z])/g, function(_, format){ 202 | var formatter = formatters[format]; 203 | if (formatter) return formatter(args[i++]); 204 | }); 205 | return (msgs[type] = msgs[type] || []).push(msg); 206 | } else if (type) { 207 | var arr = msgs[type]; 208 | delete msgs[type]; 209 | return arr || []; 210 | } else { 211 | this.session.flash = {}; 212 | return msgs; 213 | } 214 | }; 215 | 216 | /** 217 | * Check if the incoming request contains the "Content-Type" 218 | * header field, and it contains the give mime `type`. 219 | * 220 | * Examples: 221 | * 222 | * // With Content-Type: text/html; charset=utf-8 223 | * req.is('html'); 224 | * req.is('text/html'); 225 | * // => true 226 | * 227 | * // When Content-Type is application/json 228 | * req.is('json'); 229 | * req.is('application/json'); 230 | * // => true 231 | * 232 | * req.is('html'); 233 | * // => false 234 | * 235 | * Ad-hoc callbacks can also be registered with Express, to perform 236 | * assertions again the request, for example if we need an expressive 237 | * way to check if our incoming request is an image, we can register "an image" 238 | * callback: 239 | * 240 | * app.is('an image', function(req){ 241 | * return 0 == req.headers['content-type'].indexOf('image'); 242 | * }); 243 | * 244 | * Now within our route callbacks, we can use to to assert content types 245 | * such as "image/jpeg", "image/png", etc. 246 | * 247 | * app.post('/image/upload', function(req, res, next){ 248 | * if (req.is('an image')) { 249 | * // do something 250 | * } else { 251 | * next(); 252 | * } 253 | * }); 254 | * 255 | * @param {String} type 256 | * @return {Boolean} 257 | * @api public 258 | */ 259 | 260 | req.is = function(type){ 261 | var fn = this.app.is(type); 262 | if (fn) return fn(this); 263 | var contentType = this.headers['content-type']; 264 | if (!contentType) return; 265 | if (!~type.indexOf('/')) type = mime.lookup(type); 266 | if (~type.indexOf('*')) { 267 | type = type.split('/') 268 | contentType = contentType.split('/'); 269 | if ('*' == type[0] && type[1] == contentType[1]) return true; 270 | if ('*' == type[1] && type[0] == contentType[0]) return true; 271 | } 272 | return ~contentType.indexOf(type); 273 | }; 274 | 275 | // Callback for isXMLHttpRequest / xhr 276 | 277 | function isxhr() { 278 | return this.header('X-Requested-With', '').toLowerCase() === 'xmlhttprequest'; 279 | } 280 | 281 | /** 282 | * Check if the request was an _XMLHttpRequest_. 283 | * 284 | * @return {Boolean} 285 | * @api public 286 | */ 287 | 288 | req.__defineGetter__('isXMLHttpRequest', isxhr); 289 | req.__defineGetter__('xhr', isxhr); 290 | -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/qs/support/expresso/docs/index.md: -------------------------------------------------------------------------------- 1 | 2 | [Expresso](http://github.com/visionmedia/expresso) is a JavaScript [TDD](http://en.wikipedia.org/wiki/Test-driven_development) framework written for [nodejs](http://nodejs.org). Expresso is extremely fast, and is packed with features such as additional assertion methods, code coverage reporting, CI support, and more. 3 | 4 | ## Features 5 | 6 | - light-weight 7 | - intuitive async support 8 | - intuitive test runner executable 9 | - test coverage support and reporting via [node-jscoverage](http://github.com/visionmedia/node-jscoverage) 10 | - uses and extends the core _assert_ module 11 | - `assert.eql()` alias of `assert.deepEqual()` 12 | - `assert.response()` http response utility 13 | - `assert.includes()` 14 | - `assert.isNull()` 15 | - `assert.isUndefined()` 16 | - `assert.isNotNull()` 17 | - `assert.isDefined()` 18 | - `assert.match()` 19 | - `assert.length()` 20 | 21 | ## Installation 22 | 23 | To install both expresso _and_ node-jscoverage run 24 | the command below, which will first compile node-jscoverage: 25 | 26 | $ make install 27 | 28 | To install expresso alone without coverage reporting run: 29 | 30 | $ make install-expresso 31 | 32 | Install via npm: 33 | 34 | $ npm install expresso 35 | 36 | ## Examples 37 | 38 | To define tests we simply export several functions: 39 | 40 | exports['test String#length'] = function(){ 41 | assert.equal(6, 'foobar'.length); 42 | }; 43 | 44 | Alternatively for large numbers of tests you may want to 45 | export your own object containing the tests, however this 46 | is essentially the as above: 47 | 48 | module.exports = { 49 | 'test String#length': function(){ 50 | assert.equal(6, 'foobar'.length); 51 | } 52 | }; 53 | 54 | If you prefer not to use quoted keys: 55 | 56 | exports.testsStringLength = function(){ 57 | assert.equal(6, 'foobar'.length); 58 | }; 59 | 60 | The argument passed to each callback is _beforeExit_, 61 | which is typically used to assert that callbacks have been 62 | invoked. 63 | 64 | exports.testAsync = function(beforeExit){ 65 | var n = 0; 66 | setTimeout(function(){ 67 | ++n; 68 | assert.ok(true); 69 | }, 200); 70 | setTimeout(function(){ 71 | ++n; 72 | assert.ok(true); 73 | }, 200); 74 | beforeExit(function(){ 75 | assert.equal(2, n, 'Ensure both timeouts are called'); 76 | }); 77 | }; 78 | 79 | ## Assert Utilities 80 | 81 | ### assert.isNull(val[, msg]) 82 | 83 | Asserts that the given _val_ is _null_. 84 | 85 | assert.isNull(null); 86 | 87 | ### assert.isNotNull(val[, msg]) 88 | 89 | Asserts that the given _val_ is not _null_. 90 | 91 | assert.isNotNull(undefined); 92 | assert.isNotNull(false); 93 | 94 | ### assert.isUndefined(val[, msg]) 95 | 96 | Asserts that the given _val_ is _undefined_. 97 | 98 | assert.isUndefined(undefined); 99 | 100 | ### assert.isDefined(val[, msg]) 101 | 102 | Asserts that the given _val_ is not _undefined_. 103 | 104 | assert.isDefined(null); 105 | assert.isDefined(false); 106 | 107 | ### assert.match(str, regexp[, msg]) 108 | 109 | Asserts that the given _str_ matches _regexp_. 110 | 111 | assert.match('foobar', /^foo(bar)?/); 112 | assert.match('foo', /^foo(bar)?/); 113 | 114 | ### assert.length(val, n[, msg]) 115 | 116 | Assert that the given _val_ has a length of _n_. 117 | 118 | assert.length([1,2,3], 3); 119 | assert.length('foo', 3); 120 | 121 | ### assert.type(obj, type[, msg]) 122 | 123 | Assert that the given _obj_ is typeof _type_. 124 | 125 | assert.type(3, 'number'); 126 | 127 | ### assert.eql(a, b[, msg]) 128 | 129 | Assert that object _b_ is equal to object _a_. This is an 130 | alias for the core _assert.deepEqual()_ method which does complex 131 | comparisons, opposed to _assert.equal()_ which uses _==_. 132 | 133 | assert.eql('foo', 'foo'); 134 | assert.eql([1,2], [1,2]); 135 | assert.eql({ foo: 'bar' }, { foo: 'bar' }); 136 | 137 | ### assert.includes(obj, val[, msg]) 138 | 139 | Assert that _obj_ is within _val_. This method supports _Array_s 140 | and _Strings_s. 141 | 142 | assert.includes([1,2,3], 3); 143 | assert.includes('foobar', 'foo'); 144 | assert.includes('foobar', 'bar'); 145 | 146 | ### assert.response(server, req, res|fn[, msg|fn]) 147 | 148 | Performs assertions on the given _server_, which should _not_ call 149 | listen(), as this is handled internally by expresso and the server 150 | is killed after all responses have completed. This method works with 151 | any _http.Server_ instance, so _Connect_ and _Express_ servers will work 152 | as well. 153 | 154 | The _req_ object may contain: 155 | 156 | - _url_ request url 157 | - _timeout_ timeout in milliseconds 158 | - _method_ HTTP method 159 | - _data_ request body 160 | - _headers_ headers object 161 | 162 | The _res_ object may be a callback function which 163 | receives the response for assertions, or an object 164 | which is then used to perform several assertions 165 | on the response with the following properties: 166 | 167 | - _body_ assert response body (regexp or string) 168 | - _status_ assert response status code 169 | - _header_ assert that all given headers match (unspecified are ignored, use a regexp or string) 170 | 171 | When providing _res_ you may then also pass a callback function 172 | as the fourth argument for additional assertions. 173 | 174 | Below are some examples: 175 | 176 | assert.response(server, { 177 | url: '/', timeout: 500 178 | }, { 179 | body: 'foobar' 180 | }); 181 | 182 | assert.response(server, { 183 | url: '/', 184 | method: 'GET' 185 | },{ 186 | body: '{"name":"tj"}', 187 | status: 200, 188 | headers: { 189 | 'Content-Type': 'application/json; charset=utf8', 190 | 'X-Foo': 'bar' 191 | } 192 | }); 193 | 194 | assert.response(server, { 195 | url: '/foo', 196 | method: 'POST', 197 | data: 'bar baz' 198 | },{ 199 | body: '/foo bar baz', 200 | status: 200 201 | }, 'Test POST'); 202 | 203 | assert.response(server, { 204 | url: '/foo', 205 | method: 'POST', 206 | data: 'bar baz' 207 | },{ 208 | body: '/foo bar baz', 209 | status: 200 210 | }, function(res){ 211 | // All done, do some more tests if needed 212 | }); 213 | 214 | assert.response(server, { 215 | url: '/' 216 | }, function(res){ 217 | assert.ok(res.body.indexOf('tj') >= 0, 'Test assert.response() callback'); 218 | }); 219 | 220 | 221 | ## expresso(1) 222 | 223 | To run a single test suite (file) run: 224 | 225 | $ expresso test/a.test.js 226 | 227 | To run several suites we may simply append another: 228 | 229 | $ expresso test/a.test.js test/b.test.js 230 | 231 | We can also pass a whitelist of tests to run within all suites: 232 | 233 | $ expresso --only "foo()" --only "bar()" 234 | 235 | Or several with one call: 236 | 237 | $ expresso --only "foo(), bar()" 238 | 239 | Globbing is of course possible as well: 240 | 241 | $ expresso test/* 242 | 243 | When expresso is called without any files, _test/*_ is the default, 244 | so the following is equivalent to the command above: 245 | 246 | $ expresso 247 | 248 | If you wish to unshift a path to `require.paths` before 249 | running tests, you may use the `-I` or `--include` flag. 250 | 251 | $ expresso --include lib test/* 252 | 253 | The previous example is typically what I would recommend, since expresso 254 | supports test coverage via [node-jscoverage](http://github.com/visionmedia/node-jscoverage) (bundled with expresso), 255 | so you will need to expose an instrumented version of you library. 256 | 257 | To instrument your library, simply run [node-jscoverage](http://github.com/visionmedia/node-jscoverage), 258 | passing the _src_ and _dest_ directories: 259 | 260 | $ node-jscoverage lib lib-cov 261 | 262 | Now we can run our tests again, using the _lib-cov_ directory that has been 263 | instrumented with coverage statements: 264 | 265 | $ expresso -I lib-cov test/* 266 | 267 | The output will look similar to below, depending on your test coverage of course :) 268 | 269 | ![node coverage](http://dl.dropbox.com/u/6396913/cov.png) 270 | 271 | To make this process easier expresso has the _-c_ or _--cov_ which essentially 272 | does the same as the two commands above. The following two commands will 273 | run the same tests, however one will auto-instrument, and unshift _lib-cov_, 274 | and the other will run tests normally: 275 | 276 | $ expresso -I lib test/* 277 | $ expresso -I lib --cov test/* 278 | 279 | Currently coverage is bound to the _lib_ directory, however in the 280 | future `--cov` will most likely accept a path. 281 | 282 | ## Async Exports 283 | 284 | Sometimes it is useful to postpone running of tests until a callback or event has fired, currently the _exports.foo = function(){};_ syntax is supported for this: 285 | 286 | setTimeout(function(){ 287 | exports['test async exports'] = function(){ 288 | assert.ok('wahoo'); 289 | }; 290 | }, 100); 291 | -------------------------------------------------------------------------------- /test/node_modules/express/lib/router/index.js: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * Express - router 4 | * Copyright(c) 2010 TJ Holowaychuk 5 | * MIT Licensed 6 | */ 7 | 8 | /** 9 | * Module dependencies. 10 | */ 11 | 12 | var utils = require('../utils') 13 | , parse = require('url').parse 14 | , _methods = require('./methods') 15 | , Route = require('./route'); 16 | 17 | /** 18 | * Expose router. 19 | */ 20 | 21 | exports = module.exports = router; 22 | 23 | /** 24 | * Expose methods. 25 | */ 26 | 27 | exports.methods = _methods; 28 | 29 | /** 30 | * Provides Sinatra-like routing capabilities. 31 | * 32 | * @param {Function} fn 33 | * @return {Function} 34 | * @api private 35 | */ 36 | 37 | function router(fn, app){ 38 | var self = this 39 | , methods = {} 40 | , routes = {} 41 | , params = {}; 42 | 43 | if (!fn) throw new Error('router provider requires a callback function'); 44 | 45 | // Generate method functions 46 | _methods.forEach(function(method){ 47 | methods[method] = generateMethodFunction(method.toUpperCase()); 48 | }); 49 | 50 | // Alias del -> delete 51 | methods.del = methods.delete; 52 | 53 | // Apply callback to all methods 54 | methods.all = function(){ 55 | var args = arguments; 56 | _methods.forEach(function(name){ 57 | methods[name].apply(this, args); 58 | }); 59 | return self; 60 | }; 61 | 62 | // Register param callback 63 | methods.param = function(name, fn){ 64 | params[name] = fn; 65 | }; 66 | 67 | fn.call(this, methods); 68 | 69 | function generateMethodFunction(name) { 70 | var localRoutes = routes[name] = routes[name] || []; 71 | return function(path, fn){ 72 | var keys = [] 73 | , middleware = []; 74 | 75 | // slice middleware 76 | if (arguments.length > 2) { 77 | middleware = Array.prototype.slice.call(arguments, 1, arguments.length); 78 | fn = middleware.pop(); 79 | middleware = utils.flatten(middleware); 80 | } 81 | 82 | if (!path) throw new Error(name + ' route requires a path'); 83 | if (!fn) throw new Error(name + ' route ' + path + ' requires a callback'); 84 | 85 | var options = { sensitive: app.enabled('case sensitive routes') }; 86 | var route = new Route(name, path, fn, options); 87 | route.middleware = middleware; 88 | localRoutes.push(route); 89 | return self; 90 | }; 91 | } 92 | 93 | function router(req, res, next){ 94 | var route 95 | , self = this; 96 | 97 | (function pass(i){ 98 | if (route = match(req, routes, i)) { 99 | var i = 0 100 | , keys = route.keys; 101 | 102 | req.params = route.params; 103 | 104 | // Param preconditions 105 | (function param(err) { 106 | try { 107 | var key = keys[i++] 108 | , val = req.params[key] 109 | , fn = params[key]; 110 | 111 | if ('route' == err) { 112 | pass(req._route_index + 1); 113 | // Error 114 | } else if (err) { 115 | next(err); 116 | // Param has callback 117 | } else if (fn) { 118 | // Return style 119 | if (1 == fn.length) { 120 | req.params[key] = fn(val); 121 | param(); 122 | // Middleware style 123 | } else { 124 | fn(req, res, param, val); 125 | } 126 | // Finished processing params 127 | } else if (!key) { 128 | // route middleware 129 | i = 0; 130 | (function nextMiddleware(err){ 131 | var fn = route.middleware[i++]; 132 | if ('route' == err) { 133 | pass(req._route_index + 1); 134 | } else if (err) { 135 | next(err); 136 | } else if (fn) { 137 | fn(req, res, nextMiddleware); 138 | } else { 139 | route.callback.call(self, req, res, function(err){ 140 | if (err) { 141 | next(err); 142 | } else { 143 | pass(req._route_index + 1); 144 | } 145 | }); 146 | } 147 | })(); 148 | // More params 149 | } else { 150 | param(); 151 | } 152 | } catch (err) { 153 | next(err); 154 | } 155 | })(); 156 | } else if ('OPTIONS' == req.method) { 157 | options(req, res, routes); 158 | } else { 159 | next(); 160 | } 161 | })(); 162 | }; 163 | 164 | router.remove = function(path, method, ret){ 165 | var ret = ret || [] 166 | , route; 167 | 168 | // method specific remove 169 | if (method) { 170 | method = method.toUpperCase(); 171 | if (routes[method]) { 172 | for (var i = 0; i < routes[method].length; ++i) { 173 | route = routes[method][i]; 174 | if (path == route.path) { 175 | route.index = i; 176 | routes[method].splice(i, 1); 177 | ret.push(route); 178 | --i; 179 | } 180 | } 181 | } 182 | // global remove 183 | } else { 184 | _methods.forEach(function(method){ 185 | router.remove(path, method, ret); 186 | }); 187 | } 188 | 189 | return ret; 190 | }; 191 | 192 | router.lookup = function(path, method, ret){ 193 | ret = ret || []; 194 | 195 | // method specific lookup 196 | if (method) { 197 | method = method.toUpperCase(); 198 | if (routes[method]) { 199 | routes[method].forEach(function(route, i){ 200 | if (path == route.path) { 201 | route.index = i; 202 | ret.push(route); 203 | } 204 | }); 205 | } 206 | // global lookup 207 | } else { 208 | _methods.forEach(function(method){ 209 | router.lookup(path, method, ret); 210 | }); 211 | } 212 | 213 | return ret; 214 | }; 215 | 216 | router.match = function(url, method, ret){ 217 | var ret = ret || [] 218 | , i = 0 219 | , route 220 | , req; 221 | 222 | // method specific matches 223 | if (method) { 224 | method = method.toUpperCase(); 225 | req = { url: url, method: method }; 226 | while (route = match(req, routes, i)) { 227 | i = req._route_index + 1; 228 | route.index = i; 229 | ret.push(route); 230 | } 231 | // global matches 232 | } else { 233 | _methods.forEach(function(method){ 234 | router.match(url, method, ret); 235 | }); 236 | } 237 | 238 | return ret; 239 | }; 240 | 241 | return router; 242 | } 243 | 244 | /** 245 | * Respond to OPTIONS. 246 | * 247 | * @param {ServerRequest} req 248 | * @param {ServerResponse} req 249 | * @param {Array} routes 250 | * @api private 251 | */ 252 | 253 | function options(req, res, routes) { 254 | var pathname = parse(req.url).pathname 255 | , body = optionsFor(pathname, routes).join(','); 256 | res.send(body, { Allow: body }); 257 | } 258 | 259 | /** 260 | * Return OPTIONS array for the given `path`, matching `routes`. 261 | * 262 | * @param {String} path 263 | * @param {Array} routes 264 | * @return {Array} 265 | * @api private 266 | */ 267 | 268 | function optionsFor(path, routes) { 269 | return _methods.filter(function(method){ 270 | var arr = routes[method.toUpperCase()]; 271 | for (var i = 0, len = arr.length; i < len; ++i) { 272 | if (arr[i].regexp.test(path)) return true; 273 | } 274 | }).map(function(method){ 275 | return method.toUpperCase(); 276 | }); 277 | } 278 | 279 | /** 280 | * Attempt to match the given request to 281 | * one of the routes. When successful 282 | * a route function is returned. 283 | * 284 | * @param {ServerRequest} req 285 | * @param {Object} routes 286 | * @return {Function} 287 | * @api private 288 | */ 289 | 290 | function match(req, routes, i) { 291 | var captures 292 | , method = req.method 293 | , i = i || 0; 294 | 295 | // pass HEAD to GET routes 296 | if ('HEAD' == method) method = 'GET'; 297 | 298 | // routes for this method 299 | if (routes = routes[method]) { 300 | var url = parse(req.url) 301 | , pathname = url.pathname; 302 | 303 | // matching routes 304 | for (var len = routes.length; i < len; ++i) { 305 | var route = routes[i] 306 | , fn = route.callback 307 | , path = route.regexp 308 | , keys = route.keys; 309 | 310 | // match 311 | if (captures = path.exec(pathname)) { 312 | route.params = []; 313 | for (var j = 1, l = captures.length; j < l; ++j) { 314 | var key = keys[j-1], 315 | val = 'string' == typeof captures[j] 316 | ? decodeURIComponent(captures[j]) 317 | : captures[j]; 318 | if (key) { 319 | route.params[key] = val; 320 | } else { 321 | route.params.push(val); 322 | } 323 | } 324 | req._route_index = i; 325 | return route; 326 | } 327 | } 328 | } 329 | } 330 | -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/connect/lib/utils.js: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * Connect - utils 4 | * Copyright(c) 2010 Sencha Inc. 5 | * Copyright(c) 2011 TJ Holowaychuk 6 | * MIT Licensed 7 | */ 8 | 9 | /** 10 | * Module dependencies. 11 | */ 12 | 13 | var crypto = require('crypto') 14 | , Path = require('path') 15 | , fs = require('fs'); 16 | 17 | /** 18 | * Flatten the given `arr`. 19 | * 20 | * @param {Array} arr 21 | * @return {Array} 22 | * @api private 23 | */ 24 | 25 | exports.flatten = function(arr, ret){ 26 | var ret = ret || [] 27 | , len = arr.length; 28 | for (var i = 0; i < len; ++i) { 29 | if (Array.isArray(arr[i])) { 30 | exports.flatten(arr[i], ret); 31 | } else { 32 | ret.push(arr[i]); 33 | } 34 | } 35 | return ret; 36 | }; 37 | 38 | /** 39 | * Return md5 hash of the given string and optional encoding, 40 | * defaulting to hex. 41 | * 42 | * utils.md5('wahoo'); 43 | * // => "e493298061761236c96b02ea6aa8a2ad" 44 | * 45 | * @param {String} str 46 | * @param {String} encoding 47 | * @return {String} 48 | * @api public 49 | */ 50 | 51 | exports.md5 = function(str, encoding){ 52 | return crypto 53 | .createHash('md5') 54 | .update(str) 55 | .digest(encoding || 'hex'); 56 | }; 57 | 58 | /** 59 | * Merge object b with object a. 60 | * 61 | * var a = { foo: 'bar' } 62 | * , b = { bar: 'baz' }; 63 | * 64 | * utils.merge(a, b); 65 | * // => { foo: 'bar', bar: 'baz' } 66 | * 67 | * @param {Object} a 68 | * @param {Object} b 69 | * @return {Object} 70 | * @api public 71 | */ 72 | 73 | exports.merge = function(a, b){ 74 | if (a && b) { 75 | for (var key in b) { 76 | a[key] = b[key]; 77 | } 78 | } 79 | return a; 80 | }; 81 | 82 | /** 83 | * Escape the given string of `html`. 84 | * 85 | * @param {String} html 86 | * @return {String} 87 | * @api public 88 | */ 89 | 90 | exports.escape = function(html){ 91 | return String(html) 92 | .replace(/&(?!\w+;)/g, '&') 93 | .replace(//g, '>') 95 | .replace(/"/g, '"'); 96 | }; 97 | 98 | 99 | /** 100 | * Return a unique identifier with the given `len`. 101 | * 102 | * utils.uid(10); 103 | * // => "FDaS435D2z" 104 | * 105 | * @param {Number} len 106 | * @return {String} 107 | * @api public 108 | */ 109 | 110 | exports.uid = function(len) { 111 | var buf = [] 112 | , chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' 113 | , charlen = chars.length; 114 | 115 | for (var i = 0; i < len; ++i) { 116 | buf.push(chars[getRandomInt(0, charlen - 1)]); 117 | } 118 | 119 | return buf.join(''); 120 | }; 121 | 122 | /** 123 | * Parse the given cookie string into an object. 124 | * 125 | * @param {String} str 126 | * @return {Object} 127 | * @api public 128 | */ 129 | 130 | exports.parseCookie = function(str){ 131 | var obj = {} 132 | , pairs = str.split(/[;,] */); 133 | for (var i = 0, len = pairs.length; i < len; ++i) { 134 | var pair = pairs[i] 135 | , eqlIndex = pair.indexOf('=') 136 | , key = pair.substr(0, eqlIndex).trim().toLowerCase() 137 | , val = pair.substr(++eqlIndex, pair.length).trim(); 138 | 139 | // Quoted values 140 | if (val[0] === '"') { 141 | val = val.slice(1, -1); 142 | } 143 | 144 | // Only assign once 145 | if (obj[key] === undefined) { 146 | obj[key] = decodeURIComponent(val.replace(/\+/g, ' ')); 147 | } 148 | } 149 | return obj; 150 | }; 151 | 152 | /** 153 | * Serialize the given object into a cookie string. 154 | * 155 | * utils.serializeCookie('name', 'tj', { httpOnly: true }) 156 | * // => "name=tj; httpOnly" 157 | * 158 | * @param {String} name 159 | * @param {String} val 160 | * @param {Object} obj 161 | * @return {String} 162 | * @api public 163 | */ 164 | 165 | exports.serializeCookie = function(name, val, obj){ 166 | var pairs = [name + '=' + encodeURIComponent(val)] 167 | , obj = obj || {}; 168 | 169 | if (obj.domain) pairs.push('domain=' + obj.domain); 170 | if (obj.path) pairs.push('path=' + obj.path); 171 | if (obj.expires) pairs.push('expires=' + obj.expires.toUTCString()); 172 | if (obj.httpOnly) pairs.push('httpOnly'); 173 | if (obj.secure) pairs.push('secure'); 174 | 175 | return pairs.join('; '); 176 | }; 177 | 178 | /** 179 | * Pause `data` and `end` events on the given `obj`. 180 | * Middleware performing async tasks _should_ utilize 181 | * this utility (or similar), to re-emit data once 182 | * the async operation has completed, otherwise these 183 | * events may be lost. 184 | * 185 | * var pause = utils.pause(req); 186 | * fs.readFile(path, function(){ 187 | * next(); 188 | * pause.resume(); 189 | * }); 190 | * 191 | * @param {Object} obj 192 | * @return {Object} 193 | * @api public 194 | */ 195 | 196 | exports.pause = function(obj){ 197 | var onData 198 | , onEnd 199 | , events = []; 200 | 201 | // buffer data 202 | obj.on('data', onData = function(data, encoding){ 203 | events.push(['data', data, encoding]); 204 | }); 205 | 206 | // buffer end 207 | obj.on('end', onEnd = function(data, encoding){ 208 | events.push(['end', data, encoding]); 209 | }); 210 | 211 | return { 212 | end: function(){ 213 | obj.removeListener('data', onData); 214 | obj.removeListener('end', onEnd); 215 | }, 216 | resume: function(){ 217 | this.end(); 218 | for (var i = 0, len = events.length; i < len; ++i) { 219 | obj.emit.apply(obj, events[i]); 220 | } 221 | } 222 | }; 223 | }; 224 | 225 | /** 226 | * Check `req` and `res` to see if it has been modified. 227 | * 228 | * @param {IncomingMessage} req 229 | * @param {ServerResponse} res 230 | * @return {Boolean} 231 | * @api public 232 | */ 233 | 234 | exports.modified = function(req, res, headers) { 235 | var headers = headers || res._headers || {} 236 | , modifiedSince = req.headers['if-modified-since'] 237 | , lastModified = headers['last-modified'] 238 | , noneMatch = req.headers['if-none-match'] 239 | , etag = headers['etag']; 240 | 241 | if (noneMatch) noneMatch = noneMatch.split(/ *, */); 242 | 243 | // check If-None-Match 244 | if (noneMatch && etag && ~noneMatch.indexOf(etag)) { 245 | return false; 246 | } 247 | 248 | // check If-Modified-Since 249 | if (modifiedSince && lastModified) { 250 | modifiedSince = new Date(modifiedSince); 251 | lastModified = new Date(lastModified); 252 | // Ignore invalid dates 253 | if (!isNaN(modifiedSince.getTime())) { 254 | if (lastModified <= modifiedSince) return false; 255 | } 256 | } 257 | 258 | return true; 259 | }; 260 | 261 | /** 262 | * Strip `Content-*` headers from `res`. 263 | * 264 | * @param {ServerResponse} res 265 | * @api public 266 | */ 267 | 268 | exports.removeContentHeaders = function(res){ 269 | Object.keys(res._headers).forEach(function(field){ 270 | if (0 == field.indexOf('content')) { 271 | res.removeHeader(field); 272 | } 273 | }); 274 | }; 275 | 276 | /** 277 | * Check if `req` is a conditional GET request. 278 | * 279 | * @param {IncomingMessage} req 280 | * @return {Boolean} 281 | * @api public 282 | */ 283 | 284 | exports.conditionalGET = function(req) { 285 | return req.headers['if-modified-since'] 286 | || req.headers['if-none-match']; 287 | }; 288 | 289 | /** 290 | * Respond with 412 "Unauthorized". 291 | * 292 | * @param {ServerResponse} res 293 | * @param {String} realm 294 | * @api public 295 | */ 296 | 297 | exports.unauthorized = function(res, realm) { 298 | res.statusCode = 401; 299 | res.setHeader('WWW-Authenticate', 'Basic realm="' + realm + '"'); 300 | res.end('Unauthorized'); 301 | }; 302 | 303 | /** 304 | * Respond with 400 "Bad Request". 305 | * 306 | * @param {ServerResponse} res 307 | * @api public 308 | */ 309 | 310 | exports.badRequest = function(res) { 311 | res.statusCode = 400; 312 | res.end('Bad Request'); 313 | }; 314 | 315 | /** 316 | * Respond with 304 "Not Modified". 317 | * 318 | * @param {ServerResponse} res 319 | * @param {Object} headers 320 | * @api public 321 | */ 322 | 323 | exports.notModified = function(res) { 324 | exports.removeContentHeaders(res); 325 | res.statusCode = 304; 326 | res.end(); 327 | }; 328 | 329 | /** 330 | * Return an ETag in the form of `"-"` 331 | * from the given `stat`. 332 | * 333 | * @param {Object} stat 334 | * @return {String} 335 | * @api public 336 | */ 337 | 338 | exports.etag = function(stat) { 339 | return '"' + stat.size + '-' + Number(stat.mtime) + '"'; 340 | }; 341 | 342 | /** 343 | * Parse "Range" header `str` relative to the given file `size`. 344 | * 345 | * @param {Number} size 346 | * @param {String} str 347 | * @return {Array} 348 | * @api public 349 | */ 350 | 351 | exports.parseRange = function(size, str){ 352 | var valid = true; 353 | var arr = str.substr(6).split(',').map(function(range){ 354 | var range = range.split('-') 355 | , start = parseInt(range[0], 10) 356 | , end = parseInt(range[1], 10); 357 | 358 | // -500 359 | if (isNaN(start)) { 360 | start = size - end; 361 | end = size - 1; 362 | // 500- 363 | } else if (isNaN(end)) { 364 | end = size - 1; 365 | } 366 | 367 | // Invalid 368 | if (isNaN(start) || isNaN(end) || start > end) valid = false; 369 | 370 | return { start: start, end: end }; 371 | }); 372 | return valid ? arr : undefined; 373 | }; 374 | 375 | /** 376 | * Convert array-like object to an `Array`. 377 | * 378 | * node-bench measured "16.5 times faster than Array.prototype.slice.call()" 379 | * 380 | * @param {Object} obj 381 | * @return {Array} 382 | * @api public 383 | */ 384 | 385 | var toArray = exports.toArray = function(obj){ 386 | var len = obj.length 387 | , arr = new Array(len); 388 | for (var i = 0; i < len; ++i) { 389 | arr[i] = obj[i]; 390 | } 391 | return arr; 392 | }; 393 | 394 | /** 395 | * Retrun a random int, used by `utils.uid()` 396 | * 397 | * @param {Number} min 398 | * @param {Number} max 399 | * @return {Number} 400 | * @api private 401 | */ 402 | 403 | function getRandomInt(min, max) { 404 | return Math.floor(Math.random() * (max - min + 1)) + min; 405 | } 406 | -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/connect/lib/middleware/router.js: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * Connect - router 4 | * Copyright(c) 2010 Sencha Inc. 5 | * Copyright(c) 2011 TJ Holowaychuk 6 | * MIT Licensed 7 | */ 8 | 9 | /** 10 | * Module dependencies. 11 | */ 12 | 13 | var utils = require('../utils') 14 | , parse = require('url').parse; 15 | 16 | /** 17 | * Expose router. 18 | */ 19 | 20 | exports = module.exports = router; 21 | 22 | /** 23 | * Supported HTTP / WebDAV methods. 24 | */ 25 | 26 | var _methods = exports.methods = [ 27 | 'get' 28 | , 'post' 29 | , 'put' 30 | , 'delete' 31 | , 'connect' 32 | , 'options' 33 | , 'trace' 34 | , 'copy' 35 | , 'lock' 36 | , 'mkcol' 37 | , 'move' 38 | , 'propfind' 39 | , 'proppatch' 40 | , 'unlock' 41 | , 'report' 42 | , 'mkactivity' 43 | , 'checkout' 44 | , 'merge' 45 | ]; 46 | 47 | /** 48 | * Provides Sinatra and Express-like routing capabilities. 49 | * 50 | * Examples: 51 | * 52 | * connect.router(function(app){ 53 | * app.get('/user/:id', function(req, res, next){ 54 | * // populates req.params.id 55 | * }); 56 | * app.put('/user/:id', function(req, res, next){ 57 | * // populates req.params.id 58 | * }); 59 | * }) 60 | * 61 | * @param {Function} fn 62 | * @return {Function} 63 | * @api public 64 | */ 65 | 66 | function router(fn){ 67 | var self = this 68 | , methods = {} 69 | , routes = {} 70 | , params = {}; 71 | 72 | if (!fn) throw new Error('router provider requires a callback function'); 73 | 74 | // Generate method functions 75 | _methods.forEach(function(method){ 76 | methods[method] = generateMethodFunction(method.toUpperCase()); 77 | }); 78 | 79 | // Alias del -> delete 80 | methods.del = methods.delete; 81 | 82 | // Apply callback to all methods 83 | methods.all = function(){ 84 | var args = arguments; 85 | _methods.forEach(function(name){ 86 | methods[name].apply(this, args); 87 | }); 88 | return self; 89 | }; 90 | 91 | // Register param callback 92 | methods.param = function(name, fn){ 93 | params[name] = fn; 94 | }; 95 | 96 | fn.call(this, methods); 97 | 98 | function generateMethodFunction(name) { 99 | var localRoutes = routes[name] = routes[name] || []; 100 | return function(path, fn){ 101 | var keys = [] 102 | , middleware = []; 103 | 104 | // slice middleware 105 | if (arguments.length > 2) { 106 | middleware = Array.prototype.slice.call(arguments, 1, arguments.length); 107 | fn = middleware.pop(); 108 | middleware = utils.flatten(middleware); 109 | } 110 | 111 | fn.middleware = middleware; 112 | 113 | if (!path) throw new Error(name + ' route requires a path'); 114 | if (!fn) throw new Error(name + ' route ' + path + ' requires a callback'); 115 | var regexp = path instanceof RegExp 116 | ? path 117 | : normalizePath(path, keys); 118 | localRoutes.push({ 119 | fn: fn 120 | , path: regexp 121 | , keys: keys 122 | , orig: path 123 | , method: name 124 | }); 125 | return self; 126 | }; 127 | } 128 | 129 | function router(req, res, next){ 130 | var route 131 | , self = this; 132 | 133 | (function pass(i){ 134 | if (route = match(req, routes, i)) { 135 | var i = 0 136 | , keys = route.keys; 137 | 138 | req.params = route.params; 139 | 140 | // Param preconditions 141 | (function param(err) { 142 | try { 143 | var key = keys[i++] 144 | , val = req.params[key] 145 | , fn = params[key]; 146 | 147 | if ('route' == err) { 148 | pass(req._route_index + 1); 149 | // Error 150 | } else if (err) { 151 | next(err); 152 | // Param has callback 153 | } else if (fn) { 154 | // Return style 155 | if (1 == fn.length) { 156 | req.params[key] = fn(val); 157 | param(); 158 | // Middleware style 159 | } else { 160 | fn(req, res, param, val); 161 | } 162 | // Finished processing params 163 | } else if (!key) { 164 | // route middleware 165 | i = 0; 166 | (function nextMiddleware(err){ 167 | var fn = route.middleware[i++]; 168 | if ('route' == err) { 169 | pass(req._route_index + 1); 170 | } else if (err) { 171 | next(err); 172 | } else if (fn) { 173 | fn(req, res, nextMiddleware); 174 | } else { 175 | route.call(self, req, res, function(err){ 176 | if (err) { 177 | next(err); 178 | } else { 179 | pass(req._route_index + 1); 180 | } 181 | }); 182 | } 183 | })(); 184 | // More params 185 | } else { 186 | param(); 187 | } 188 | } catch (err) { 189 | next(err); 190 | } 191 | })(); 192 | } else if ('OPTIONS' == req.method) { 193 | options(req, res, routes); 194 | } else { 195 | next(); 196 | } 197 | })(); 198 | }; 199 | 200 | router.remove = function(path, method){ 201 | var fns = router.lookup(path, method); 202 | fns.forEach(function(fn){ 203 | routes[fn.method].splice(fn.index, 1); 204 | }); 205 | }; 206 | 207 | router.lookup = function(path, method, ret){ 208 | ret = ret || []; 209 | 210 | // method specific lookup 211 | if (method) { 212 | method = method.toUpperCase(); 213 | if (routes[method]) { 214 | routes[method].forEach(function(route, i){ 215 | if (path == route.orig) { 216 | var fn = route.fn; 217 | fn.regexp = route.path; 218 | fn.keys = route.keys; 219 | fn.path = route.orig; 220 | fn.method = route.method; 221 | fn.index = i; 222 | ret.push(fn); 223 | } 224 | }); 225 | } 226 | // global lookup 227 | } else { 228 | _methods.forEach(function(method){ 229 | router.lookup(path, method, ret); 230 | }); 231 | } 232 | 233 | return ret; 234 | }; 235 | 236 | router.match = function(url, method, ret){ 237 | var ret = ret || [] 238 | , i = 0 239 | , fn 240 | , req; 241 | 242 | // method specific matches 243 | if (method) { 244 | method = method.toUpperCase(); 245 | req = { url: url, method: method }; 246 | while (fn = match(req, routes, i)) { 247 | i = req._route_index + 1; 248 | ret.push(fn); 249 | } 250 | // global matches 251 | } else { 252 | _methods.forEach(function(method){ 253 | router.match(url, method, ret); 254 | }); 255 | } 256 | 257 | return ret; 258 | }; 259 | 260 | return router; 261 | } 262 | 263 | /** 264 | * Respond to OPTIONS. 265 | * 266 | * @param {ServerRequest} req 267 | * @param {ServerResponse} req 268 | * @param {Array} routes 269 | * @api private 270 | */ 271 | 272 | function options(req, res, routes) { 273 | var pathname = parse(req.url).pathname 274 | , body = optionsFor(pathname, routes).join(','); 275 | res.writeHead(200, { 276 | 'Content-Length': body.length 277 | , 'Allow': body 278 | }); 279 | res.end(body); 280 | } 281 | 282 | /** 283 | * Return OPTIONS array for the given `path`, matching `routes`. 284 | * 285 | * @param {String} path 286 | * @param {Array} routes 287 | * @return {Array} 288 | * @api private 289 | */ 290 | 291 | function optionsFor(path, routes) { 292 | return _methods.filter(function(method){ 293 | var arr = routes[method.toUpperCase()]; 294 | for (var i = 0, len = arr.length; i < len; ++i) { 295 | if (arr[i].path.test(path)) return true; 296 | } 297 | }).map(function(method){ 298 | return method.toUpperCase(); 299 | }); 300 | } 301 | 302 | /** 303 | * Normalize the given path string, 304 | * returning a regular expression. 305 | * 306 | * An empty array should be passed, 307 | * which will contain the placeholder 308 | * key names. For example "/user/:id" will 309 | * then contain ["id"]. 310 | * 311 | * @param {String} path 312 | * @param {Array} keys 313 | * @return {RegExp} 314 | * @api private 315 | */ 316 | 317 | function normalizePath(path, keys) { 318 | path = path 319 | .concat('/?') 320 | .replace(/\/\(/g, '(?:/') 321 | .replace(/(\/)?(\.)?:(\w+)(?:(\(.*?\)))?(\?)?/g, function(_, slash, format, key, capture, optional){ 322 | keys.push(key); 323 | slash = slash || ''; 324 | return '' 325 | + (optional ? '' : slash) 326 | + '(?:' 327 | + (optional ? slash : '') 328 | + (format || '') + (capture || '([^/]+?)') + ')' 329 | + (optional || ''); 330 | }) 331 | .replace(/([\/.])/g, '\\$1') 332 | .replace(/\*/g, '(.+)'); 333 | return new RegExp('^' + path + '$', 'i'); 334 | } 335 | 336 | /** 337 | * Attempt to match the given request to 338 | * one of the routes. When successful 339 | * a route function is returned. 340 | * 341 | * @param {ServerRequest} req 342 | * @param {Object} routes 343 | * @return {Function} 344 | * @api private 345 | */ 346 | 347 | function match(req, routes, i) { 348 | var captures 349 | , method = req.method 350 | , i = i || 0; 351 | if ('HEAD' == method) method = 'GET'; 352 | if (routes = routes[method]) { 353 | var url = parse(req.url) 354 | , pathname = url.pathname; 355 | for (var len = routes.length; i < len; ++i) { 356 | var route = routes[i] 357 | , fn = route.fn 358 | , path = route.path 359 | , keys = fn.keys = route.keys; 360 | if (captures = path.exec(pathname)) { 361 | fn.method = method; 362 | fn.params = []; 363 | for (var j = 1, len = captures.length; j < len; ++j) { 364 | var key = keys[j-1], 365 | val = typeof captures[j] === 'string' 366 | ? decodeURIComponent(captures[j]) 367 | : captures[j]; 368 | if (key) { 369 | fn.params[key] = val; 370 | } else { 371 | fn.params.push(val); 372 | } 373 | } 374 | req._route_index = i; 375 | return fn; 376 | } 377 | } 378 | } 379 | } 380 | -------------------------------------------------------------------------------- /test/node_modules/express/node_modules/connect/lib/middleware/session.js: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * Connect - session 4 | * Copyright(c) 2010 Sencha Inc. 5 | * Copyright(c) 2011 TJ Holowaychuk 6 | * MIT Licensed 7 | */ 8 | 9 | /** 10 | * Module dependencies. 11 | */ 12 | 13 | var Session = require('./session/session') 14 | , MemoryStore = require('./session/memory') 15 | , Cookie = require('./session/cookie') 16 | , Store = require('./session/store') 17 | , utils = require('./../utils') 18 | , parse = require('url').parse 19 | , crypto = require('crypto'); 20 | 21 | // environment 22 | 23 | var env = process.env.NODE_ENV; 24 | 25 | /** 26 | * Expose the middleware. 27 | */ 28 | 29 | exports = module.exports = session; 30 | 31 | /** 32 | * Expose constructors. 33 | */ 34 | 35 | exports.Store = Store; 36 | exports.Cookie = Cookie; 37 | exports.Session = Session; 38 | exports.MemoryStore = MemoryStore; 39 | 40 | /** 41 | * Warning message for `MemoryStore` usage in production. 42 | */ 43 | 44 | var warning = 'Warning: connection.session() MemoryStore is not\n' 45 | + 'designed for a production environment, as it will leak\n' 46 | + 'memory, and obviously only work within a single process.'; 47 | 48 | /** 49 | * Default finger-printing function. 50 | */ 51 | 52 | function defaultFingerprint(req) { 53 | return req.headers['user-agent'] || ''; 54 | }; 55 | 56 | /** 57 | * Paths to ignore, defaulting to `/favicon.ico`. 58 | */ 59 | 60 | exports.ignore = ['/favicon.ico']; 61 | 62 | /** 63 | * Setup session store with the given `options`. 64 | * 65 | * Session data is _not_ saved in the cookie itself, however 66 | * cookies are used, so we must use the [cookieParser()](middleware-cookieParser.html) 67 | * middleware _before_ `session()`. 68 | * 69 | * Examples: 70 | * 71 | * connect.createServer( 72 | * connect.cookieParser() 73 | * , connect.session({ secret: 'keyboard cat' }) 74 | * ); 75 | * 76 | * Options: 77 | * 78 | * - `key` cookie name defaulting to `connect.sid` 79 | * - `store` Session store instance 80 | * - `fingerprint` Custom fingerprint generating function 81 | * - `cookie` Session cookie settings, defaulting to `{ path: '/', httpOnly: true, maxAge: 14400000 }` 82 | * - `secret` Secret string used to compute hash 83 | * 84 | * Ignore Paths: 85 | * 86 | * By default `/favicon.ico` is the only ignored path, all others 87 | * will utilize sessions, to manipulate the paths ignored, use 88 | * `connect.session.ignore.push('/my/path')`. This works for _full_ 89 | * pathnames only, not segments nor substrings. 90 | * 91 | * connect.session.ignore.push('/robots.txt'); 92 | * 93 | * ## req.session 94 | * 95 | * To store or access session data, simply use the request property `req.session`, 96 | * which is (generally) serialized as JSON by the store, so nested objects 97 | * are typically fine. For example below is a user-specific view counter: 98 | * 99 | * connect( 100 | * connect.cookieParser() 101 | * , connect.session({ secret: 'keyboard cat', cookie: { maxAge: 60000 }}) 102 | * , connect.favicon() 103 | * , function(req, res, next){ 104 | * var sess = req.session; 105 | * if (sess.views) { 106 | * res.setHeader('Content-Type', 'text/html'); 107 | * res.write('

    views: ' + sess.views + '

    '); 108 | * res.write('

    expires in: ' + (sess.cookie.maxAge / 1000) + 's

    '); 109 | * res.end(); 110 | * sess.views++; 111 | * } else { 112 | * sess.views = 1; 113 | * res.end('welcome to the session demo. refresh!'); 114 | * } 115 | * } 116 | * ).listen(3000); 117 | * 118 | * ## Session#regenerate() 119 | * 120 | * To regenerate the session simply invoke the method, once complete 121 | * a new SID and `Session` instance will be initialized at `req.session`. 122 | * 123 | * req.session.regenerate(function(err){ 124 | * // will have a new session here 125 | * }); 126 | * 127 | * ## Session#destroy() 128 | * 129 | * Destroys the session, removing `req.session`, will be re-generated next request. 130 | * 131 | * req.session.destroy(function(err){ 132 | * // cannot access session here 133 | * }); 134 | * 135 | * ## Session#touch() 136 | * 137 | * Updates the `.maxAge`, and `.lastAccess` properties. Typically this is 138 | * not necessary to call, as the session middleware does this for you. 139 | * 140 | * ## Session#cookie 141 | * 142 | * Each session has a unique cookie object accompany it. This allows 143 | * you to alter the session cookie per visitor. For example we can 144 | * set `req.session.cookie.expires` to `false` to enable the cookie 145 | * to remain for only the duration of the user-agent. 146 | * 147 | * ## Session#maxAge 148 | * 149 | * Alternatively `req.session.cookie.maxAge` will return the time 150 | * remaining in milliseconds, which we may also re-assign a new value 151 | * to adjust the `.expires` property appropriately. The following 152 | * are essentially equivalent 153 | * 154 | * var hour = 3600000; 155 | * req.session.cookie.expires = new Date(Date.now() + hour); 156 | * req.session.cookie.maxAge = hour; 157 | * 158 | * For example when `maxAge` is set to `60000` (one minute), and 30 seconds 159 | * has elapsed it will return `30000` until the current request has completed, 160 | * at which time `req.session.touch()` is called to update `req.session.lastAccess`, 161 | * and reset `req.session.maxAge` to its original value. 162 | * 163 | * req.session.cookie.maxAge; 164 | * // => 30000 165 | * 166 | * Session Store Implementation: 167 | * 168 | * Every session store _must_ implement the following methods 169 | * 170 | * - `.get(sid, callback)` 171 | * - `.set(sid, session, callback)` 172 | * - `.destroy(sid, callback)` 173 | * 174 | * Recommended methods include, but are not limited to: 175 | * 176 | * - `.length(callback)` 177 | * - `.clear(callback)` 178 | * 179 | * For an example implementation view the [connect-redis](http://github.com/visionmedia/connect-redis) repo. 180 | * 181 | * @param {Object} options 182 | * @return {Function} 183 | * @api public 184 | */ 185 | 186 | function session(options){ 187 | var options = options || {} 188 | , key = options.key || 'connect.sid' 189 | , secret = options.secret 190 | , store = options.store || new MemoryStore 191 | , fingerprint = options.fingerprint || defaultFingerprint 192 | , cookie = options.cookie; 193 | 194 | // notify user that this store is not 195 | // meant for a production environment 196 | if ('production' == env && store instanceof MemoryStore) { 197 | console.warn(warning); 198 | } 199 | 200 | // ensure secret is present 201 | if (!secret) { 202 | throw new Error('connect.session({ secret: "string" }) required for security'); 203 | } 204 | 205 | // session hashing function 206 | store.hash = function(req, base) { 207 | return crypto 208 | .createHmac('sha256', secret) 209 | .update(base + fingerprint(req)) 210 | .digest('base64') 211 | .replace(/=*$/, ''); 212 | }; 213 | 214 | // generates the new session 215 | store.generate = function(req){ 216 | var base = utils.uid(24); 217 | var sessionID = base + '.' + store.hash(req, base); 218 | req.sessionID = sessionID; 219 | req.session = new Session(req); 220 | req.session.cookie = new Cookie(cookie); 221 | }; 222 | 223 | return function session(req, res, next) { 224 | // self-awareness 225 | if (req.session) return next(); 226 | 227 | // parse url 228 | var url = parse(req.url) 229 | , path = url.pathname; 230 | 231 | // ignorable paths 232 | if (~exports.ignore.indexOf(path)) return next(); 233 | 234 | // expose store 235 | req.sessionStore = store; 236 | 237 | // proxy writeHead() to Set-Cookie 238 | var writeHead = res.writeHead; 239 | res.writeHead = function(status, headers){ 240 | if (req.session) { 241 | var cookie = req.session.cookie; 242 | // only send secure session cookies when there is a secure connection. 243 | // proxySecure is a custom attribute to allow for a reverse proxy 244 | // to handle SSL connections and to communicate to connect over HTTP that 245 | // the incoming connection is secure. 246 | var secured = cookie.secure && (req.connection.encrypted || req.connection.proxySecure); 247 | if (secured || !cookie.secure) { 248 | res.setHeader('Set-Cookie', cookie.serialize(key, req.sessionID)); 249 | } 250 | } 251 | 252 | res.writeHead = writeHead; 253 | return res.writeHead(status, headers); 254 | }; 255 | 256 | // proxy end() to commit the session 257 | var end = res.end; 258 | res.end = function(data, encoding){ 259 | res.end = end; 260 | if (req.session) { 261 | // HACK: ensure Set-Cookie for implicit writeHead() 262 | if (!res._header) res._implicitHeader(); 263 | req.session.resetMaxAge(); 264 | req.session.save(function(){ 265 | res.end(data, encoding); 266 | }); 267 | } else { 268 | res.end(data, encoding); 269 | } 270 | }; 271 | 272 | // session hashing 273 | function hash(base) { 274 | return store.hash(req, base); 275 | } 276 | 277 | // generate the session 278 | function generate() { 279 | store.generate(req); 280 | } 281 | 282 | // get the sessionID from the cookie 283 | req.sessionID = req.cookies[key]; 284 | 285 | // make a new session if the browser doesn't send a sessionID 286 | if (!req.sessionID) { 287 | generate(); 288 | next(); 289 | return; 290 | } 291 | 292 | // check the fingerprint 293 | var parts = req.sessionID.split('.'); 294 | if (parts[1] != hash(parts[0])) { 295 | generate(); 296 | next(); 297 | return; 298 | } 299 | 300 | // generate the session object 301 | var pause = utils.pause(req); 302 | store.get(req.sessionID, function(err, sess){ 303 | // proxy to resume() events 304 | var _next = next; 305 | next = function(err){ 306 | _next(err); 307 | pause.resume(); 308 | } 309 | 310 | // error handling 311 | if (err) { 312 | if ('ENOENT' == err.code) { 313 | generate(); 314 | next(); 315 | } else { 316 | next(err); 317 | } 318 | // no session 319 | } else if (!sess) { 320 | generate(); 321 | next(); 322 | // populate req.session 323 | } else { 324 | store.createSession(req, sess); 325 | next(); 326 | } 327 | }); 328 | }; 329 | }; 330 | --------------------------------------------------------------------------------