/**
 * Define a response method to redirect.
 * @function serverside.res.defineResRedirect
 * @param {object} context - Server context object.
 * @param {number} context.REDIRECT_STATUS_CODE - Status code.
 * @returns {function} - Res redirect function.
 * @author Taka Okunishi
 *
 */
var format = require('util').format;
exports = module.exports = function (context) {
    context.assertKeys(['REDIRECT_STATUS_CODE']);

    var statusCode = context.REDIRECT_STATUS_CODE;
    return function (path) {
        var res = this;
        res.setHeader('Location', path);
        res.statusCode = statusCode;
        var msg = encodeURIComponent(format('Redirecting to %s', path));
        res.end(msg);
    }
};