Skip to content
Myr

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

4 files+11 added−10 removed

modified:lib/response.js+5 added-5 removed
18 unmodified lines
19var http = require('http');20var isAbsolute = require('./utils').isAbsolute;21var onFinished = require('on-finished');22var path = require('path');23var statuses = require('statuses')24var merge = require('utils-merge');25var sign = require('cookie-signature').sign;26var normalizeType = require('./utils').normalizeType;27var normalizeTypes = require('./utils').normalizeTypes;28var setCharset = require('./utils').setCharset;28var statusCodes = http.STATUS_CODES;29var cookie = require('cookie');30var send = require('send');31var extname = path.extname;32var mime = send.mime;
95 unmodified lines
128 }129130 deprecate('res.send(status): Use res.sendStatus(status) instead');131 this.statusCode = chunk;132 chunk = statusCodes[chunk];132 chunk = statuses[chunk]133 }134135 switch (typeof chunk) {136 // string defaulting to html
196 unmodified lines
333 * @public334 */335336res.sendStatus = function sendStatus(statusCode) {337 var body = statusCodes[statusCode] || String(statusCode);337 var body = statuses[statusCode] || String(statusCode)338339 this.statusCode = statusCode;340 this.type('txt');341
533 unmodified lines
875876 // 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 },881882 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 },886887 default: function(){888 body = '';
177 unmodified lines
modified:test/res.redirect.js+4 added-5 removed
12var http = require('http');2var express = require('..');3var request = require('supertest');4var utils = require('./support/utils');5
96 unmodified lines
102 .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 })108109 it('should escape the url', function(done){110 var app = express();
7 unmodified lines
118 .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&#39;me%3E">%3Cla&#39;me%3E</a></p>', done)122 .expect(302, '<p>Found. Redirecting to <a href="%3Cla&#39;me%3E">%3Cla&#39;me%3E</a></p>', done)123 })124125 it('should include the redirect type', function(done){126 var app = express();
23 unmodified lines
150 .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 })156157 it('should encode the url', function(done){158 var app = express();
7 unmodified lines
166 .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 })172173 it('should include the redirect type', function(done){174 var app = express();
32 unmodified lines
modified:History.md+1 added
2 unmodified lines
34 * 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 Native
3191 unmodified lines
modified:package.json+1 added