parent
51d33edb79
commit
12f92a50dc
@ -1,6 +1,7 @@
|
||||
unreleased
|
||||
==========
|
||||
|
||||
* Add `res.sendStatus`
|
||||
* Invoke callback for sendfile when client aborts
|
||||
- Applies to `res.sendFile`, `res.sendfile`, and `res.download`
|
||||
- `err` will be populated with request aborted error
|
||||
|
@ -303,6 +303,30 @@ res.jsonp = function jsonp(obj) {
|
||||
return this.send(body);
|
||||
};
|
||||
|
||||
/**
|
||||
* Send given HTTP status code.
|
||||
*
|
||||
* Sets the response status to `statusCode` and the body of the
|
||||
* response to the standard description from node's http.STATUS_CODES
|
||||
* or the statusCode number if no description.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* res.sendStatus(200);
|
||||
*
|
||||
* @param {number} statusCode
|
||||
* @api public
|
||||
*/
|
||||
|
||||
res.sendStatus = function sendStatus(statusCode) {
|
||||
var body = http.STATUS_CODES[statusCode] || String(statusCode);
|
||||
|
||||
this.statusCode = statusCode;
|
||||
this.type('txt');
|
||||
|
||||
return this.send(body);
|
||||
};
|
||||
|
||||
/**
|
||||
* Transfer the file at the given `path`.
|
||||
*
|
||||
|
32
test/res.sendStatus.js
Normal file
32
test/res.sendStatus.js
Normal file
@ -0,0 +1,32 @@
|
||||
|
||||
var assert = require('assert')
|
||||
var express = require('..')
|
||||
var request = require('supertest')
|
||||
|
||||
describe('res', function () {
|
||||
describe('.sendStatus(statusCode)', function () {
|
||||
it('should send the status code and message as body', function (done) {
|
||||
var app = express();
|
||||
|
||||
app.use(function(req, res){
|
||||
res.sendStatus(201);
|
||||
});
|
||||
|
||||
request(app)
|
||||
.get('/')
|
||||
.expect(201, 'Created', done);
|
||||
})
|
||||
|
||||
it('should work with unknown code', function (done) {
|
||||
var app = express();
|
||||
|
||||
app.use(function(req, res){
|
||||
res.sendStatus(599);
|
||||
});
|
||||
|
||||
request(app)
|
||||
.get('/')
|
||||
.expect(599, '599', done);
|
||||
})
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue
Block a user