Merge branch 'master' of github.com:visionmedia/express
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Tj Holowaychuk · committed by Tj Holowaychuk · parents 4d4dfc2, 1444439 · Browse files · 9 files·+77 added−15 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
9 files+77 added−15 removed
- tests:+51 added−5 removed
- other:+26 added−10 removed
Provenance
- Commit
838a51d- Tree
5f04759- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent 1
4d4dfc2- Parent 2
1444439
9 files changed+77 added−15 removed
modified:docs/guide.md+3 added
472 unmodified lines473 The `res.send()` method is a high level response utility allowing you to pass474 objects to respond with json, strings for html, arbitrary _Buffer_s or numbers for status475 code based responses. The following are all valid uses:476 477+ res.send(); // 204478 res.send(new Buffer('wahoo'));479 res.send({ some: 'json' });480 res.send('<p>some html</p>');481 res.send('Sorry, cant find that', 404);29 unmodified lines511 512 - _context|scope_ Template evaluation context (_this_)513 - _locals_ Object containing local variables514 - _debug_ Output debugging information515+ - _status_ Response status code, defaults to 200516+ - _headers_ Response headers object517 518 ### res.partial(view[, options])519 520 Render _view_ partial with the given _options_. This method is always available200 unmodified linesmodified:examples/pages/app.js+5 added-3 removed
51 unmodified lines5253545556575859606 unmodified lines67686970717071727273747576777814 unmodified lines51 unmodified lines
app.error(function(err, req, res, next){ if (err instanceof NotFound) { res.render('404.jade', { status: 404, locals: { error: err } });6 unmodified lines// this demo, however you can choose whatever you like
app.error(function(err, req, res){ res.render('500.jade', { status: 500, locals: { error: err } locals: { error: err } });});
// Routes14 unmodified linesmodified:lib/express/response.js+12 added
27 unmodified lines28 * Send a response with the given `body` and optional `headers` and `status` code.29 *30 * Examples:31 *32+ * res.send();33 * res.send(new Buffer('wahoo'));34 * res.send({ some: 'json' });35 * res.send('<p>some html</p>');36 * res.send('Sorry, cant find that', 404);16 unmodified lines53 54 // Defaults55 status = status || 200;56 57+ // Allow 0 args as 20458+ if (!arguments.length) {59+ body = status = 204;60+ }61+62 // Determine content type63 switch (typeof body) {64 case 'number':65 if (!this.headers['Content-Type']) {35 unmodified lines101 this.header(field, headers[field]);102 }103 }104 105+ // Strip irrelevant headers106+ if (204 === status) {107+ delete this.headers['Content-Type'];108+ delete this.headers['Content-Length'];109+ }110+111 // Respond112 this.writeHead(status, this.headers);113 this.end(body);114 };172 unmodified linesmodified:lib/express/view.js+3 added-1 removed
168 unmodified lines169 *170 * - `context|scope` Template evaluation context (`this`)171 * - `locals` Object containing local variables172 * - `debug` Output debugging information173+ * - `status` Response status code, defaults to 200174+ * - `headers` Response headers object175 *176 * @param {String} view177 * @param {Object|Function} options or callback function178 * @param {Function} fn117 unmodified lines296 return str;297 } else if (fn) {298 fn(null, str);299 } else {298- self.send(str);300+ self.send(str, options.headers, options.status);301 }302 };modified:test/fixtures/dynamic-helpers.jade+1 added-1 removed
1-p #{session.name} #{lastName} #{foo()}1+p #{greetings(session, lastName)}modified:test/response.test.js+10 added
34 unmodified lines35 36 app.get('/buffer', function(req, res){37 res.send(new Buffer('wahoo!'));38 });39+ 40+ app.get('/noargs', function(req, res, next){41+ res.send();42+ });43 44 assert.response(app,45 { url: '/html' },46 { body: '<p>test</p>', headers: { 'Content-Language': 'en', 'Content-Type': 'text/html; charset=utf-8' }});11 unmodified lines58 { body: 'Oh shit!', status: 500, headers: { 'Content-Type': 'text/plain' }});59 assert.response(app,60 { url: '/buffer' },61 { body: 'wahoo!', headers: { 'Content-Type': 'application/octet-stream' }});62+ assert.response(app,63+ { url: '/noargs' },64+ { status: 204 }, function(res){65+ assert.equal(undefined, res.headers['content-type']);66+ assert.equal(undefined, res.headers['content-length']);67+ });68 },69 70 'test #contentType()': function(assert){71 var app = express.createServer();170 unmodified linesmodified:test/view.test.js+40 added-4 removed
206 unmodified lines207 { url: '/custom' },208 { body: '<p>2</p>'});209 },210 211+ 'test #render() status': function(assert){212+ var app = create();213+ 214+ app.get('/', function(req, res){215+ res.render('hello.jade', {216+ layout: false,217+ status: 404218+ });219+ });220+ 221+ assert.response(app,222+ { url: '/' },223+ { body: '<p>:(</p>', status: 404 });224+ },225+ 226+ 'test #render() headers': function(assert){227+ var app = create();228+ 229+ app.get('/', function(req, res){230+ res.render('hello.jade', {231+ layout: false,232+ status: 500,233+ headers: {234+ 'X-Foo': 'bar'235+ }236+ });237+ });238+ 239+ assert.response(app,240+ { url: '/' },241+ { body: '<p>:(</p>', status: 500, headers: {242+ 'X-Foo': 'bar',243+ 'Content-Type': 'text/html; charset=utf-8'244+ }});245+ },246+ 247 'test #render() view helpers': function(assert){248 var app = create();249 250 app.helpers({ 251 lastName: 'holowaychuk',216- foo: function(){217- return 'bar'; 252+ greetings: function(sess, lastName){253+ return 'Hello ' + sess.name + ' ' + lastName; 254 }255 });256 257 var ret = app.dynamicHelpers({22 unmodified lines280 });281 282 assert.response(app,283 { url: '/' },248- { body: '<p>tj holowaychuk bar</p>' });284+ { body: '<p>Hello tj holowaychuk</p>' });285 assert.response(app,286 { url: '/precedence' },251- { body: '<p>tj foobar bar</p>' });287+ { body: '<p>Hello tj foobar</p>' });288 },289 290 'test #partial()': function(assert){291 var app = create();203 unmodified linesmodified:package.json+1 added-1 removed
11 unmodified lines1213141516161711 unmodified lines "keywords": ["framework", "sinatra", "web", "rest", "restful"], "directories": { "lib": "./lib/express" }, "scripts": { "test": "make test" }, "bin": { "express": "./bin/express" }, "engines": { "node": ">= 0.1.101" } "engines": { "node": ">= 0.2.0" }}No newline at end of fileNo newline at end of filemodified:Readme.md+2 added-5 removed
64 unmodified lines65 * Guillermo Rauch ([guille](http://github.com/guille))66 67 ## More Information68 69+ * Express [Contrib](http://github.com/visionmedia/express-contrib) repo for additional functionality70 * Follow [tjholowaychuk](http://twitter.com/tjholowaychuk) on twitter for updates71 * [Google Group](http://groups.google.com/group/express-js) for discussion71- * [JavaScript Extensions & Utilities](http://github.com/visionmedia/ext.js)72- * [JavaScript Sass](http://github.com/visionmedia/sass.js)73- * [JavaScript Haml](http://github.com/visionmedia/haml.js)74- * [JavaScript Jade](http://github.com/visionmedia/jade) Haml successor75- * [Boilerplate](http://github.com/robrighter/node-boilerplate) boilerplate app supplying Express, Connect, Socket-IO, Jade and more.72+ * Visit the [Wiki](http://github.com/visionmedia/express/wiki)73 74 ## Node Compatibility75 76 The latest release of Express is compatible with node --version:31 unmodified lines