Merge branch 'master' of git://github.com/visionmedia/express
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ciaranj · committed by ciaranj · parents 3f9cbbb, 4f4b4f0 · Browse files · 15 files·+103 added−63 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
15 files+103 added−63 removed
- tests:+51 added−34 removed
- other:+52 added−29 removed
Provenance
- Commit
e125ae2- Tree
028501d- Author
ciaranj <ciaranj@gmail.com>- Committer
ciaranj <ciaranj@gmail.com>- Parent 1
3f9cbbb- Parent 2
4f4b4f0
15 files changed+103 added−63 removed
modified:examples/app.js+4 added
53 unmodified lines54555657585960616253 unmodified linesget('/error', function(){ throw new Error('oh noes!')})
get('/simple', function(){ return 'Hello :)'})
run()No newline at end of fileNo newline at end of filemodified:lib/express/pages/not-found.js+1 added-1 removed
4 unmodified lines5678991011121316 unmodified lines4 unmodified lines
exports.render = function(request) { request.contentType('html') var method = request.method.toLowerCase(), path = request.uri.path || '/' path = request.url.pathname || '/' return '<html> \n\ <head> \n\ <title>Express -- Not Found</title> \n\ ' + style + ' \n\16 unmodified linesmodified:lib/express/pages/show-exceptions.js+2 added-2 removed
64 unmodified lines6566676869697071727373747576777864 unmodified lines ' + hash(request.params) + ' \n\ </table> \n\ <h3>GET</h3> \n\ <table id="get-params"> \n\ ' + hash(request.uri.params) + ' \n\ ' + hash(request.url.params) + ' \n\ </table> \n\ <h3>POST</h3> \n\ <table id="post-params"> \n\ ' + hash(request.uri.post) + ' \n\ ' + hash(request.url.post) + ' \n\ </table> \n\ </div> \n\ </body> \n\ </html>'}modified:lib/express/plugins/common-logger.js+1 added-1 removed
39 unmodified lines40 puts([event.request.headers.host, 41 '-', 42 '-',43 '[' + format(new Date) + ']', 44- '"' + event.request.method.toUpperCase() + ' ' + (event.request.uri.path || '/') + 44+ '"' + event.request.method.toUpperCase() + ' ' + (event.request.url.pathname || '/') + 45 ' HTTP/' + event.request.httpVersion + '"',46 event.request.response.status,47 event.request.response.headers['content-length'] || 0].join(' '))48 }2 unmodified linesmodified:lib/express/plugins/profiler.js+1 added-1 removed
16 unmodified lines1718192021212223242516 unmodified lines */ response: function(event) { puts(event.request.method + ' ' + event.request.uri.path + ': ' + event.request.url.pathname + ': ' + (Number(new Date) - this.start) + ' ms') } }})No newline at end of fileNo newline at end of filemodified:lib/express/plugins/redirect.js+5 added-5 removed
10 unmodified lines11 init: function() {12 Request.include({13 14 /**15- * Redirect to _uri_ with optional status _code_,15+ * Redirect to _url_ with optional status _code_,16 * defaulting to 303 "See Other".17 *18 * When using redirect('home') the resolution19 * is as follows:5 unmodified lines25 * When using redirect('back') the HTTP referrer26 * header is used. Commonly misspelled as 'referer'27 * which is supported as well.28 *29- * @param {string} uri29+ * @param {string} url30 * @settings 'home', 'basepath'31 * @api public32 */33 34- redirect: function(uri, code) {35- if (uri == 'back' || uri == 'home') uri = this[uri]36- this.header('location', uri)34+ redirect: function(url, code) {35+ if (url == 'back' || url == 'home') url = this[url]36+ this.header('location', url)37 this.halt(code || 303)38 } 39 })40 }17 unmodified linesmodified:lib/express/spec/mocks.js+1 added-7 removed
20 unmodified lines21 */22 23 init: function(method, path, options) {24 this.method = method25+ this.url = path26 this.connection = {27 remoteAddress: '127.0.0.1'28 }28- this.uri = {29- queryString: '',30- fragment: '',31- params: {},32- path: path,33- full: path34- }29 this.headers = {30 'host': 'localhost',31 'user-agent': 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; en-us) AppleWebKit/530.19.2 (KHTML, like Gecko) Version/4.0.2 Safari/530.19',32 'accept': 'application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5',97 unmodified linesmodified:lib/express/core.js+2 added-2 removed
93 unmodified lines94 95 Router = Class({96 97 /**98- * Initialize with _request_.98+ * Initialize with _request_ and parse url.99 *100 * @param {Request} request101 * @api private102 */43 unmodified lines146 */147 148 match: function(route) {149 if (this.request.method.toLowerCase() == route.method)150- if (this.request.captures = this.request.uri.path.match(route.path)) {150+ if (this.request.captures = this.request.url.pathname.match(route.path)) {151 this.mapParams(route)152 return true153 }154 },124 unmodified linesmodified:lib/express/helpers.js+5 added-4 removed
133 unmodified lines134 return params135 }136 137 /**138- * Parse params _string_ into a nested hash.138+ * Parse params _str_ into a nested hash.139 *140- * @param {string} string140+ * @param {string} str141 * @return {hash}142 * @api public143 */144 145-exports.parseParams = function(string) {146- return exports.parseNestedParams($(string.split('&')).reduce({}, function(params, pair){145+exports.parseParams = function(str) {146+ if (typeof str !== 'string') return147+ return exports.parseNestedParams($(str.split('&')).reduce({}, function(params, pair){148 pair = pair.split('=')149 params[pair[0]] = pair[1]150 return params151 }))1 unmodified linemodified:lib/express/request.js+14 added-11 removed
1 2 // Express - Request - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)3 4 /**5- * StaticFile for Request#sendfile()5+ * Module dependencies.6 */7 8-var StaticFile = require('express/static').File8+var StaticFile = require('express/static').File,9+ statusBodies = require('http').STATUS_CODES,10+ url = require('url')11 10-/**11- * Default response code bodies.12- */13-14-var statusBodies = require('http').STATUS_CODES15-12 // --- InvalidStatusCode13 14 InvalidStatusCode = ExpressError.extend({15 name: 'InvalidStatusCode',6 unmodified lines22 23 InvalidResponseBody = ExpressError.extend({24 name: 'InvalidResponseBody',25 init: function(request) {30- this.message = request.method + ' ' + JSON.encode(request.uri.path) + ' did not respond with a body string'26+ this.message = request.method + ' ' + JSON.encode(request.url.pathname) + ' did not respond with a body string'27 }28 })29 30 // --- Helpers17 unmodified lines48 49 /**50 * Initialize with node's _request_ and _response_ objects.51 *52+ * - Defaults headers to {}53+ * - Parses request url54+ * - Normalizes url pathname55+ * - Parses GET params when available56+ * - Initializes plugins57+ *58 * @param {object} request59 * @param {object} response60 * @api private61 */1 unmodified line63 init: function(request, response) {64 process.mixin(true, this, request)65 response.headers = {}66 this.response = response65- this.uri.path = exports.normalizePath(this.uri.path)67+ this.url = url.parse(this.url)68+ this.url.pathname = exports.normalizePath(this.url.pathname)69 this.params = { 67- get: parseNestedParams(this.uri.params), 70+ get: parseParams(this.url.query) || {}, 71 post: {}, 72 path: {}73 }74 this.plugins = $(Express.plugins).map(function(plugin){189 unmodified linesmodified:spec/node.js+46 added-23 removed
15 unmodified lines16 .wait()17 return result18 }19 20-if (process.ARGV[2])21- JSpec.exec('spec/spec.' + process.ARGV[2] + '.js') 22-else23- JSpec24- .exec('spec/spec.core.js')25- .exec('spec/spec.routing.js')26- .exec('spec/spec.helpers.js')27- .exec('spec/spec.request.js')28- .exec('spec/spec.mime.js')29- .exec('spec/spec.static.js')30- .exec('spec/spec.collection.js')31- .exec('spec/spec.element-collection.js')32- .exec('spec/spec.plugins.js')33- .exec('spec/spec.plugins.view.js')34- .exec('spec/spec.plugins.common-logger.js')35- .exec('spec/spec.plugins.content-length.js')36- .exec('spec/spec.plugins.method-override.js')37- .exec('spec/spec.plugins.body-decoder.js')38- .exec('spec/spec.plugins.redirect.js')39- .exec('spec/spec.plugins.hooks.js')40- .exec('spec/spec.plugins.cookie.js')41-JSpec.run({ reporter: JSpec.reporters.Terminal, failuresOnly: true })42-JSpec.report()20+function run(specs) {21+ specs.forEach(function(spec){22+ JSpec.exec('spec/spec.' + spec + '.js')23+ })24+}25+26+specs = {27+ independant: [28+ 'core',29+ 'routing',30+ 'helpers',31+ 'request',32+ 'mime',33+ 'static',34+ 'collection',35+ 'plugins',36+ 'plugins.view',37+ 'plugins.common-logger',38+ 'plugins.content-length',39+ 'plugins.method-override',40+ 'plugins.body-decoder',41+ 'plugins.redirect',42+ 'plugins.hooks',43+ 'plugins.cookie',44+ ],45+ dependant: [46+ 'element-collection'47+ ]48+}49+50+switch (process.ARGV[2]) {51+ case 'independant':52+ run(specs.independant)53+ break54+ case 'dependant':55+ run(specs.dependant)56+ break57+ case 'all':58+ run(specs.independant)59+ run(specs.dependant)60+ break61+ default: 62+ run([process.ARGV[2]])63+}64+65+JSpec.run({ reporter: JSpec.reporters.Terminal, failuresOnly: true }).report()modified:spec/spec.plugins.method-override.js+2 added-2 removed
10 unmodified lines11 it 'should consider _method as the HTTP method'12 put('/user', function(){13 return 'updated user'14 })15- post('/user', { uri: { params: { _method: 'put' }}}).body.should.eql 'updated user'15+ post('/user', { body: '_method=put', headers: { 'content-type': 'application/x-www-form-urlencoded' }}).body.should.eql 'updated user'16 end17 18 it 'should force _method to lowercase to conform to internal uses'19 put('/user', function(){20 return 'updated user'21 })22- post('/user', { uri: { params: { _method: 'PUT' }}}).body.should.eql 'updated user'22+ post('/user', { body: '_method=PUT', headers: { 'content-type': 'application/x-www-form-urlencoded' }}).body.should.eql 'updated user'23 end24 end25 end26 end1 unmodified linemodified:spec/spec.request.js+2 added-2 removed
152 unmodified lines153 get('/user/12').body.should.eql '12'154 get('/product/ipod').body.should.eql 'ipod'155 end156 157- it 'should access request.uri.params'157+ it 'should access request.url.params'158 get('/user', function(){159 return this.param('page') || 'First page'160 })161 get('/user').body.should.eql 'First page'162- get('/user', { uri: { params: { page: '2' }}}).body.should.eql '2'162+ get('/user?page=2').body.should.eql '2'163 end164 165 it 'should work with splats'166 get('/:path/*.*', function(path, file, ext){7 unmodified linesmodified:Makefile+7 added-1 removed
3 unmodified lines4 init: lib/support/js-oo/Readme.md5 @git submodule update --init6 7 test: init spec/support/libxmljs/libxmljs.node8- @$(NODE) spec/node.js8+ @$(NODE) spec/node.js all9 10+test-independant: init11+ @$(NODE) spec/node.js independant12+ 13+test-dependant: init spec/support/libxmljs/libxmljs.node14+ @$(NODE) spec/node.js dependant15+ 16 app:17 @$(NODE) examples/app.js18 19 benchmark:6 unmodified linesmodified:Readme.md+10 added-1 removed
86 unmodified lines87 related dependencies such as libxmljs.88 89 $ make test90 91+To run independant specs (which do not require building of external apis etc) use:92+93+ $ make test-independant94+ 95+To run dependant specs (which require building of external apis etc) use:96+97+ $ make test-dependant98+ 99 Run individual suites:100 101 $ node spec/node.js core102 $ node spec/node.js mime103 $ node spec/node.js routing104 ...105 106 Express is currently being developed with node --version:99- v0.1.21-66-g59a78d6107+ v0.1.24-13-ge2abc5f108 109 ## More Information110 111 * [JavaScript Extensions & Utilities](http://github.com/visionmedia/ext.js)112 * [JavaScript Sass](http://github.com/visionmedia/sass.js)113+ * [Scons Build System](http://www.scons.org/) (some development dependencies rely on this, ex libxmljs)114 115 ## Contributors116 117 * TJ Holowaychuk (visionmedia) <tj@vision-media.ca>27 unmodified lines