Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace http.STATUS_CODES with the statuses module #3215

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ 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 statuses = require('statuses')
var cookie = require('cookie');
var send = require('send');
var extname = path.extname;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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 = '<p>' + statusCodes[status] + '. Redirecting to <a href="' + u + '">' + u + '</a></p>';
body = '<p>' + statuses[status] + '. Redirecting to <a href="' + u + '">' + u + '</a></p>'
},

default: function(){
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 4 additions & 5 deletions test/res.redirect.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

var http = require('http');
var express = require('..');
var request = require('supertest');
var utils = require('./support/utils');
Expand Down Expand Up @@ -104,7 +103,7 @@ describe('res', function(){
.set('Accept', 'text/html')
.expect('Content-Type', /html/)
.expect('Location', 'http://google.com')
.expect(302, '<p>' + http.STATUS_CODES[302] + '. Redirecting to <a href="http://google.com">http://google.com</a></p>', done);
.expect(302, '<p>Found. Redirecting to <a href="http://google.com">http://google.com</a></p>', done)
})

it('should escape the url', function(done){
Expand All @@ -120,7 +119,7 @@ describe('res', function(){
.set('Accept', 'text/html')
.expect('Content-Type', /html/)
.expect('Location', '%3Cla\'me%3E')
.expect(302, '<p>' + http.STATUS_CODES[302] + '. Redirecting to <a href="%3Cla&#39;me%3E">%3Cla&#39;me%3E</a></p>', done)
.expect(302, '<p>Found. Redirecting to <a href="%3Cla&#39;me%3E">%3Cla&#39;me%3E</a></p>', done)
})

it('should include the redirect type', function(done){
Expand Down Expand Up @@ -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){
Expand All @@ -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){
Expand Down