Skip to content
Myr

refactored res.redirect() with respondTo()

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 e229118 · Browse files · 2 files+10 added−8 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+10 added−8 removed

  • tests:+1 added−1 removed
  • other:+9 added−7 removed

2 files+10 added−8 removed

modified:lib/response.js+9 added-7 removed
539 unmodified lines
540 url = req.protocol + '://' + host + url;541 }542543 // Support text/{plain,html} by default544 if (req.accepts('html')) {545 body = '<p>' + statusCodes[status] + '. Redirecting to <a href="' + url + '">' + url + '</a></p>';546 this.set('Content-Type', 'text/html');547 } else {548 body = statusCodes[status] + '. Redirecting to ' + url;549 this.set('Content-Type', 'text/plain');550 }544 this.respondTo({545 'text/plain': function(){546 body = statusCodes[status] + '. Redirecting to ' + url;547 },548549 'text/html': function(){550 body = '<p>' + statusCodes[status] + '. Redirecting to <a href="' + url + '">' + url + '</a></p>';551 }552 })553554 // Respond555 this.statusCode = status;556 this.set('Location', url);557 this.end(head ? null : body);
72 unmodified lines
modified:test/res.redirect.js+1 added-1 removed
243 unmodified lines
244 });245246 request(app)247 .get('/')248 .set('Accept', 'text/plain')248 .set('Accept', 'text/plain, */*')249 .end(function(res){250 res.headers.should.have.property('location', 'http://google.com');251 res.body.should.equal('Moved Temporarily. Redirecting to http://google.com');252 done();
4 unmodified lines