Skip to content
Myr

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

15 files+103 added−63 removed

modified:examples/app.js+4 added
modified:lib/express/pages/not-found.js+1 added-1 removed
modified:lib/express/pages/show-exceptions.js+2 added-2 removed
modified:lib/express/plugins/common-logger.js+1 added-1 removed
39 unmodified lines
40 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 lines
modified:lib/express/plugins/profiler.js+1 added-1 removed
modified:lib/express/plugins/redirect.js+5 added-5 removed
10 unmodified lines
11 init: function() {12 Request.include({1314 /**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 lines
25 * 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 */3334 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 lines
modified:lib/express/spec/mocks.js+1 added-7 removed
20 unmodified lines
21 */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 lines
modified:lib/express/core.js+2 added-2 removed
93 unmodified lines
9495Router = Class({96 97 /**98 * Initialize with _request_.98 * Initialize with _request_ and parse url.99 *100 * @param {Request} request101 * @api private102 */
43 unmodified lines
146 */147148 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 lines
modified:lib/express/helpers.js+5 added-4 removed
133 unmodified lines
134 return params135}136137/**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 */144145exports.parseParams = function(string) {146 return exports.parseNestedParams($(string.split('&')).reduce({}, function(params, pair){145exports.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 line
modified:lib/express/request.js+14 added-11 removed
12// Express - Request - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)34/**5 * StaticFile for Request#sendfile()5 * Module dependencies.6 */78var StaticFile = require('express/static').File8var StaticFile = require('express/static').File,9 statusBodies = require('http').STATUS_CODES,10 url = require('url')1110/**11 * Default response code bodies.12 */1314var statusBodies = require('http').STATUS_CODES1512// --- InvalidStatusCode1314InvalidStatusCode = ExpressError.extend({15 name: 'InvalidStatusCode',
6 unmodified lines
2223InvalidResponseBody = 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})2930// --- Helpers
17 unmodified lines
48 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 line
63 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 lines
modified:spec/node.js+46 added-23 removed
15 unmodified lines
16 .wait()17 return result18}1920if (process.ARGV[2])21 JSpec.exec('spec/spec.' + process.ARGV[2] + '.js') 22else23 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')41JSpec.run({ reporter: JSpec.reporters.Terminal, failuresOnly: true })42JSpec.report()20function run(specs) {21 specs.forEach(function(spec){22 JSpec.exec('spec/spec.' + spec + '.js')23 })24}2526specs = {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}4950switch (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}6465JSpec.run({ reporter: JSpec.reporters.Terminal, failuresOnly: true }).report()
modified:spec/spec.plugins.method-override.js+2 added-2 removed
10 unmodified lines
11 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 end
1 unmodified line
modified:spec/spec.request.js+2 added-2 removed
152 unmodified lines
153 get('/user/12').body.should.eql '12'154 get('/product/ipod').body.should.eql 'ipod'155 end156157 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 end164165 it 'should work with splats'166 get('/:path/*.*', function(path, file, ext){
7 unmodified lines
modified:Makefile+7 added-1 removed
3 unmodified lines
4init: lib/support/js-oo/Readme.md5 @git submodule update --init67test: init spec/support/libxmljs/libxmljs.node8 @$(NODE) spec/node.js8 @$(NODE) spec/node.js all9 10test-independant: init11 @$(NODE) spec/node.js independant12 13test-dependant: init spec/support/libxmljs/libxmljs.node14 @$(NODE) spec/node.js dependant15 16app:17 @$(NODE) examples/app.js18 19benchmark:
6 unmodified lines
modified:Readme.md+10 added-1 removed
86 unmodified lines
87related dependencies such as libxmljs.8889 $ make test90 91To run independant specs (which do not require building of external apis etc) use:9293 $ make test-independant94 95To run dependant specs (which require building of external apis etc) use:9697 $ make test-dependant98 99Run individual suites:100101 $ node spec/node.js core102 $ node spec/node.js mime103 $ node spec/node.js routing104 ...105 106Express is currently being developed with node --version:99 v0.1.21-66-g59a78d6107 v0.1.24-13-ge2abc5f108 109## More Information110111 * [JavaScript Extensions &amp; 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## Contributors116117 * TJ Holowaychuk (visionmedia) &lt;tj@vision-media.ca&gt;
27 unmodified lines