Skip to content
Browse files

Added optional status-code to redirect method

  • Loading branch information...
1 parent f26fe38 commit ab3b28f043a6d0a350f9c9d48d6af3eaa030a9de mde committed
Showing with 13 additions and 3 deletions.
  1. +13 −3 lib/controller/base_controller.js
View
16 lib/controller/base_controller.js
@@ -464,7 +464,7 @@ controller.BaseController.prototype = new (function () {
this.before(_protectFromForgery, opts);
};
- this.redirect = function (target) {
+ this.redirect = function (target, options) {
/*
@name controller.BaseController#redirect
@public
@@ -473,8 +473,18 @@ controller.BaseController.prototype = new (function () {
simple string-URL, or a controller/action/format combination.
@param {String|Object} target Either an URL, or an object literal containing
controller/action/format attributes to base the redirect on.
+ @param {Object} [options] Options.
+ @param {Number} [options.statusCode] The HTTP status-code to use for the
+ redirect.
*/
- var url;
+ var url
+ , opts = options || {}
+ , statusCode = opts.statusCode || 302;
+
+ // Make sure it's a 3xx
+ if (String(statusCode).indexOf('3') != 0) {
+ throw new Error('Redirect status must be 3xx');
+ }
if (typeof target == 'string') {
url = target
@@ -504,7 +514,7 @@ controller.BaseController.prototype = new (function () {
}
}
- this._doResponse(302, { 'Location': url }, '');
+ this._doResponse(statusCode, { 'Location': url }, '');
};
this.error = function (err) {

0 comments on commit ab3b28f

Please sign in to comment.
Something went wrong with that request. Please try again.