Added http status code string representation to res.redirect() body
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent 0bc7e24 · Browse files · 2 files·+17 added−15 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+17 added−15 removed
- tests:+11 added−11 removed
- other:+6 added−4 removed
Provenance
- Commit
3914895- Tree
413513a- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
0bc7e24
2 files changed+17 added−15 removed
modified:lib/express/response.js+6 added-4 removed
333 unmodified lines334 * @api public335 */336 337 http.ServerResponse.prototype.redirect = function(url, status){338- var body, basePath = this.app.set('home') || '/';338+ var basePath = this.app.set('home') || '/'339+ , status = status || 302340+ , body;341 342 // Setup redirect map343 var map = {344 back: this.req.headers.referrer || this.req.headers.referer || basePath,12 unmodified lines357 url = mapped || url;358 359 // Support text/{plain,html} by default360 if (this.req.accepts('html')) {359- body = '<p>Redirecting to <a href="' + url + '">' + url + '</a></p>';361+ body = '<p>' + http.STATUS_CODES[status] + '. Redirecting to <a href="' + url + '">' + url + '</a></p>';362 this.header('Content-Type', 'text/html');363 } else {362- body = 'Redirecting to ' + url;364+ body = http.STATUS_CODES[status] + '. Redirecting to ' + url;365 this.header('Content-Type', 'text/plain');366 }367 368 // Respond367- this.send(body, { Location: url }, status || 302);369+ this.send(body, { Location: url }, status);370 };modified:test/response.test.js+11 added-11 removed
174 unmodified lines175 176 177 assert.response(app,178 { url: '/html', headers: { Accept: 'text/html,text/plain' }},179- { body: '<p>Redirecting to <a href="http://google.com">http://google.com</a></p>' });179+ { body: '<p>Moved Temporarily. Redirecting to <a href="http://google.com">http://google.com</a></p>' });180 assert.response(app,181 { url: '/', headers: { Accept: 'text/plain' }},182- { body: 'Redirecting to http://google.com', status: 301, headers: { Location: 'http://google.com' }});182+ { body: 'Moved Permanently. Redirecting to http://google.com', status: 301, headers: { Location: 'http://google.com' }});183 assert.response(app,184 { url: '/back', headers: { Accept: 'text/plain' }},185- { body: 'Redirecting to /', status: 302, headers: { Location: '/', 'Content-Type': 'text/plain' }});185+ { body: 'Moved Temporarily. Redirecting to /', status: 302, headers: { Location: '/', 'Content-Type': 'text/plain' }});186 assert.response(app,187 { url: '/back', headers: { Referer: '/foo', Accept: 'text/plain' }},188- { body: 'Redirecting to /foo', status: 302, headers: { Location: '/foo' }});188+ { body: 'Moved Temporarily. Redirecting to /foo', status: 302, headers: { Location: '/foo' }});189 assert.response(app,190 { url: '/back', headers: { Referrer: '/foo', Accept: 'text/plain' }},191- { body: 'Redirecting to /foo', status: 302, headers: { Location: '/foo' }});191+ { body: 'Moved Temporarily. Redirecting to /foo', status: 302, headers: { Location: '/foo' }});192 assert.response(app,193 { url: '/home', headers: { Accept: 'text/plain' } },194- { body: 'Redirecting to /', status: 302, headers: { Location: '/' }});194+ { body: 'Moved Temporarily. Redirecting to /', status: 302, headers: { Location: '/' }});195 196 assert.response(app2,197 { url: '/', headers: { Accept: 'text/plain' }},198- { body: 'Redirecting to http://google.com', status: 301, headers: { Location: 'http://google.com' }});198+ { body: 'Moved Permanently. Redirecting to http://google.com', status: 301, headers: { Location: 'http://google.com' }});199 assert.response(app2,200 { url: '/back', headers: { Accept: 'text/plain' }},201- { body: 'Redirecting to /blog', status: 302, headers: { Location: '/blog' }});201+ { body: 'Moved Temporarily. Redirecting to /blog', status: 302, headers: { Location: '/blog' }});202 assert.response(app2,203 { url: '/home', headers: { Accept: 'text/plain' }},204- { body: 'Redirecting to /blog', status: 302, headers: { Location: '/blog' }});204+ { body: 'Moved Temporarily. Redirecting to /blog', status: 302, headers: { Location: '/blog' }});205 assert.response(app2,206 { url: '/google', headers: { Accept: 'text/plain' }},207- { body: 'Redirecting to http://google.com', headers: { Location: 'http://google.com' }});207+ { body: 'Moved Temporarily. Redirecting to http://google.com', status: 302, headers: { Location: 'http://google.com' }});208 assert.response(app2,209 { url: '/user/12', headers: { Accept: 'text/plain' }},210- { body: 'Redirecting to /user/12/blog', headers: { Location: '/user/12/blog', 'X-Foo': 'bar' }});210+ { body: 'Moved Temporarily. Redirecting to /user/12/blog', status: 302, headers: { Location: '/user/12/blog', 'X-Foo': 'bar' }});211 },212 213 'test #sendfile()': function(assert){214 var app = express.createServer();194 unmodified lines