Skip to content

Commit

Permalink
Use redirect method on response if available
Browse files Browse the repository at this point in the history
  • Loading branch information
mde committed Oct 28, 2012
1 parent 140539c commit f5f13bb
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions lib/passport/context/http/actions.js
Expand Up @@ -46,9 +46,23 @@ actions.fail = function(challenge, status) {
* @api public
*/
actions.redirect = function(url, status) {
this.res.statusCode = status || 302;
this.res.setHeader('Location', url);
this.res.end();
var res = this.res;
// If possible use redirect method on the response
if (typeof res.redirect == 'function') {
// Assume Express API, optional status param comes first
if (status) {
res.redirect(status, url);
}
else {
res.redirect(url);
}
}
// Otherwise fall back to native methods
else {
res.statusCode = status || 302;
res.setHeader('Location', url);
res.end();
}
}

/**
Expand Down

0 comments on commit f5f13bb

Please sign in to comment.