Skip to content
Myr

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

9 files+77 added−15 removed

modified:docs/guide.md+3 added
472 unmodified lines
473The `res.send()` method is a high level response utility allowing you to pass474objects to respond with json, strings for html, arbitrary _Buffer_s or numbers for status475code based responses. The following are all valid uses:476477 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 lines
511512 - _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 object517518### res.partial(view[, options])519520Render _view_ partial with the given _options_. This method is always available
200 unmodified lines
modified:examples/pages/app.js+5 added-3 removed
modified:lib/express/response.js+12 added
27 unmodified lines
28 * 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 lines
5354 // Defaults55 status = status || 200;5657 // Allow 0 args as 20458 if (!arguments.length) {59 body = status = 204;60 }6162 // Determine content type63 switch (typeof body) {64 case 'number':65 if (!this.headers['Content-Type']) {
35 unmodified lines
101 this.header(field, headers[field]);102 }103 }104105 // Strip irrelevant headers106 if (204 === status) {107 delete this.headers['Content-Type'];108 delete this.headers['Content-Length'];109 }110111 // Respond112 this.writeHead(status, this.headers);113 this.end(body);114};
172 unmodified lines
modified:lib/express/view.js+3 added-1 removed
168 unmodified lines
169 *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} fn
117 unmodified lines
296 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
1p #{session.name} #{lastName} #{foo()}1p #{greetings(session, lastName)}
modified:test/response.test.js+10 added
34 unmodified lines
35 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 });4344 assert.response(app,45 { url: '/html' },46 { body: '<p>test</p>', headers: { 'Content-Language': 'en', 'Content-Type': 'text/html; charset=utf-8' }});
11 unmodified lines
58 { 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 lines
modified:test/view.test.js+40 added-4 removed
206 unmodified lines
207 { 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();249250 app.helpers({ 251 lastName: 'holowaychuk',216 foo: function(){217 return 'bar'; 252 greetings: function(sess, lastName){253 return 'Hello ' + sess.name + ' ' + lastName; 254 }255 });256257 var ret = app.dynamicHelpers({
22 unmodified lines
280 });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 lines
modified:package.json+1 added-1 removed
modified:Readme.md+2 added-5 removed
64 unmodified lines
65 * Guillermo Rauch ([guille](http://github.com/guille))6667## More Information6869 * 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 &amp; 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)7374## Node Compatibility75 76The latest release of Express is compatible with node --version:
31 unmodified lines