diff --git a/History.md b/History.md index 7e90ca96..a74b4c05 100644 --- a/History.md +++ b/History.md @@ -4,6 +4,7 @@ unreleased * Add debug message when loading view engine * Remove usage of `res._headers` private field - Improves compatibility with Node.js 8 nightly + * Use `statuses` instead of `http` module for status messages * deps: debug@2.6.1 - Allow colors in workers - Deprecated `DEBUG_FD` environment variable set to `3` or higher diff --git a/lib/response.js b/lib/response.js index 6128f450..42bc196d 100644 --- a/lib/response.js +++ b/lib/response.js @@ -20,12 +20,12 @@ var http = require('http'); var isAbsolute = require('./utils').isAbsolute; var onFinished = require('on-finished'); var path = require('path'); +var statuses = require('statuses') var merge = require('utils-merge'); var sign = require('cookie-signature').sign; var normalizeType = require('./utils').normalizeType; var normalizeTypes = require('./utils').normalizeTypes; var setCharset = require('./utils').setCharset; -var statusCodes = http.STATUS_CODES; var cookie = require('cookie'); var send = require('send'); var extname = path.extname; @@ -129,7 +129,7 @@ res.send = function send(body) { deprecate('res.send(status): Use res.sendStatus(status) instead'); this.statusCode = chunk; - chunk = statusCodes[chunk]; + chunk = statuses[chunk] } switch (typeof chunk) { @@ -334,7 +334,7 @@ res.jsonp = function jsonp(obj) { */ res.sendStatus = function sendStatus(statusCode) { - var body = statusCodes[statusCode] || String(statusCode); + var body = statuses[statusCode] || String(statusCode) this.statusCode = statusCode; this.type('txt'); @@ -876,12 +876,12 @@ res.redirect = function redirect(url) { // Support text/{plain,html} by default this.format({ text: function(){ - body = statusCodes[status] + '. Redirecting to ' + address; + body = statuses[status] + '. Redirecting to ' + address }, html: function(){ var u = escapeHtml(address); - body = '
' + statusCodes[status] + '. Redirecting to ' + u + '
'; + body = '' + statuses[status] + '. Redirecting to ' + u + '
' }, default: function(){ diff --git a/package.json b/package.json index 417df65d..36d83cb9 100644 --- a/package.json +++ b/package.json @@ -50,6 +50,7 @@ "range-parser": "~1.2.0", "send": "0.14.2", "serve-static": "~1.11.2", + "statuses": "~1.3.1", "type-is": "~1.6.14", "utils-merge": "1.0.0", "vary": "~1.1.0" diff --git a/test/res.redirect.js b/test/res.redirect.js index 9f3bd436..755bb1c1 100644 --- a/test/res.redirect.js +++ b/test/res.redirect.js @@ -1,5 +1,4 @@ -var http = require('http'); var express = require('..'); var request = require('supertest'); var utils = require('./support/utils'); @@ -104,7 +103,7 @@ describe('res', function(){ .set('Accept', 'text/html') .expect('Content-Type', /html/) .expect('Location', 'http://google.com') - .expect(302, '' + http.STATUS_CODES[302] + '. Redirecting to http://google.com
', done); + .expect(302, 'Found. Redirecting to http://google.com
', done) }) it('should escape the url', function(done){ @@ -120,7 +119,7 @@ describe('res', function(){ .set('Accept', 'text/html') .expect('Content-Type', /html/) .expect('Location', '%3Cla\'me%3E') - .expect(302, '' + http.STATUS_CODES[302] + '. Redirecting to %3Cla'me%3E
', done) + .expect(302, 'Found. Redirecting to %3Cla'me%3E
', done) }) it('should include the redirect type', function(done){ @@ -152,7 +151,7 @@ describe('res', function(){ .set('Accept', 'text/plain, */*') .expect('Content-Type', /plain/) .expect('Location', 'http://google.com') - .expect(302, http.STATUS_CODES[302] + '. Redirecting to http://google.com', done); + .expect(302, 'Found. Redirecting to http://google.com', done) }) it('should encode the url', function(done){ @@ -168,7 +167,7 @@ describe('res', function(){ .set('Accept', 'text/plain, */*') .expect('Content-Type', /plain/) .expect('Location', 'http://example.com/?param=%3Cscript%3Ealert(%22hax%22);%3C/script%3E') - .expect(302, http.STATUS_CODES[302] + '. Redirecting to http://example.com/?param=%3Cscript%3Ealert(%22hax%22);%3C/script%3E', done) + .expect(302, 'Found. Redirecting to http://example.com/?param=%3Cscript%3Ealert(%22hax%22);%3C/script%3E', done) }) it('should include the redirect type', function(done){