Use statuses instead of http module for status messages
Before adoption: this commit came in with the history the project adopted, so no landing records it.
closes #3215
authored by Wes · committed by Douglas Christopher Wilson · parent a9f15aa · Browse files · 4 files·+11 added−10 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+11 added−10 removed
- tests:+4 added−5 removed
- other:+7 added−5 removed
Provenance
- Commit
034165c- Tree
6a1fb69- Author
Wes <wes@wesleytodd.com>- Committer
Douglas Christopher Wilson <doug@somethingdoug.com>- Parent
a9f15aa
4 files changed+11 added−10 removed
modified:lib/response.js+5 added-5 removed
18 unmodified lines19 var http = require('http');20 var isAbsolute = require('./utils').isAbsolute;21 var onFinished = require('on-finished');22 var path = require('path');23+var statuses = require('statuses')24 var merge = require('utils-merge');25 var sign = require('cookie-signature').sign;26 var normalizeType = require('./utils').normalizeType;27 var normalizeTypes = require('./utils').normalizeTypes;28 var setCharset = require('./utils').setCharset;28-var statusCodes = http.STATUS_CODES;29 var cookie = require('cookie');30 var send = require('send');31 var extname = path.extname;32 var mime = send.mime;95 unmodified lines128 }129 130 deprecate('res.send(status): Use res.sendStatus(status) instead');131 this.statusCode = chunk;132- chunk = statusCodes[chunk];132+ chunk = statuses[chunk]133 }134 135 switch (typeof chunk) {136 // string defaulting to html196 unmodified lines333 * @public334 */335 336 res.sendStatus = function sendStatus(statusCode) {337- var body = statusCodes[statusCode] || String(statusCode);337+ var body = statuses[statusCode] || String(statusCode)338 339 this.statusCode = statusCode;340 this.type('txt');341 533 unmodified lines875 876 // Support text/{plain,html} by default877 this.format({878 text: function(){879- body = statusCodes[status] + '. Redirecting to ' + address;879+ body = statuses[status] + '. Redirecting to ' + address880 },881 882 html: function(){883 var u = escapeHtml(address);884- body = '<p>' + statusCodes[status] + '. Redirecting to <a href="' + u + '">' + u + '</a></p>';884+ body = '<p>' + statuses[status] + '. Redirecting to <a href="' + u + '">' + u + '</a></p>'885 },886 887 default: function(){888 body = '';177 unmodified linesmodified:test/res.redirect.js+4 added-5 removed
1 2-var http = require('http');2 var express = require('..');3 var request = require('supertest');4 var utils = require('./support/utils');5 96 unmodified lines102 .get('/')103 .set('Accept', 'text/html')104 .expect('Content-Type', /html/)105 .expect('Location', 'http://google.com')107- .expect(302, '<p>' + http.STATUS_CODES[302] + '. Redirecting to <a href="http://google.com">http://google.com</a></p>', done);106+ .expect(302, '<p>Found. Redirecting to <a href="http://google.com">http://google.com</a></p>', done)107 })108 109 it('should escape the url', function(done){110 var app = express();7 unmodified lines118 .set('Host', 'http://example.com')119 .set('Accept', 'text/html')120 .expect('Content-Type', /html/)121 .expect('Location', '%3Cla\'me%3E')123- .expect(302, '<p>' + http.STATUS_CODES[302] + '. Redirecting to <a href="%3Cla'me%3E">%3Cla'me%3E</a></p>', done)122+ .expect(302, '<p>Found. Redirecting to <a href="%3Cla'me%3E">%3Cla'me%3E</a></p>', done)123 })124 125 it('should include the redirect type', function(done){126 var app = express();23 unmodified lines150 .get('/')151 .set('Accept', 'text/plain, */*')152 .expect('Content-Type', /plain/)153 .expect('Location', 'http://google.com')155- .expect(302, http.STATUS_CODES[302] + '. Redirecting to http://google.com', done);154+ .expect(302, 'Found. Redirecting to http://google.com', done)155 })156 157 it('should encode the url', function(done){158 var app = express();7 unmodified lines166 .set('Host', 'http://example.com')167 .set('Accept', 'text/plain, */*')168 .expect('Content-Type', /plain/)169 .expect('Location', 'http://example.com/?param=%3Cscript%3Ealert(%22hax%22);%3C/script%3E')171- .expect(302, http.STATUS_CODES[302] + '. Redirecting to http://example.com/?param=%3Cscript%3Ealert(%22hax%22);%3C/script%3E', done)170+ .expect(302, 'Found. Redirecting to http://example.com/?param=%3Cscript%3Ealert(%22hax%22);%3C/script%3E', done)171 })172 173 it('should include the redirect type', function(done){174 var app = express();32 unmodified linesmodified:History.md+1 added
2 unmodified lines3 4 * Add debug message when loading view engine5 * Remove usage of `res._headers` private field6 - Improves compatibility with Node.js 8 nightly7+ * Use `statuses` instead of `http` module for status messages8 * deps: debug@2.6.19 - Allow colors in workers10 - Deprecated `DEBUG_FD` environment variable set to `3` or higher11 - Fix error when running under React Native3191 unmodified linesmodified:package.json+1 added
48 unmodified lines49505152535455565737 unmodified lines48 unmodified lines "qs": "6.3.1", "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" },37 unmodified lines