Skip to content
Myr

Added chainable res.status(code)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

ex: res.status(500).send("lame")

authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent 9e4020e · Browse files · 2 files+17 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+17 added−0 removed

  • tests:+12 added−0 removed
  • other:+5 added−0 removed

2 files+17 added−0 removed

modified:lib/response.js+5 added
138 unmodified lines
139 this.header('Content-Type', 'application/json');140 return this.send(JSON.stringify(obj), headers, status);141};142143res.status = function(code){144 this.statusCode = code;145 return this;146};147148/**149 * Transfer the file at the given `path`. Automatically sets 150 * the _Content-Type_ response header field. `next()` is called151 * when `path` is a directory, or when an error occurs.
300 unmodified lines
modified:test/response.test.js+12 added
46 unmodified lines
47 { url: '/user' },48 { body: '{"name":"tj"}', headers: { 'Content-Type': json }});49 },5051 'test #status()': function(){52 var app = express.createServer();5354 app.get('/error', function(req, res, next){55 res.status(500).send('OH NO');56 });5758 assert.response(app,59 { url: '/error' },60 { body: 'OH NO', status: 500 });61 },6263 'test #send()': function(){64 var app = express.createServer();65 66 app.get('/html', function(req, res){
606 unmodified lines