129 unmodified lines
Expand all
? this.headers[name]
: this.headers[name] = val;
};
/**
* Redirect to the given `url` with optional response `status`
* defauling to 302.
*
* The given `url` can also be the name of a mapped url, for
* example by default express supports "back" which redirects
* to the _Referrer_ or _Referer_ headers or the application's
* "home" setting. Express also supports "home" out of the box,
* which can be set via `app.set('home', '/blog');`, and defaults
* to '/'.
*
* Extended Redirect Map:
*
* app.redirect = {
* google: 'http://google.com',
* blog: '/some/blog'
* };
*
* @param {String} url
* @param {Number} code
* @api public
*/
http.ServerResponse.prototype.redirect = function(url, code){
http.ServerResponse.prototype.redirect = function(url, status){
var basePath = this.app.set('home') || '/';
// Setup redirect map
var map = {
map.__proto__ = this.app.redirect;
}
// Perform redirect
this.writeHead(code || 302, {
this.writeHead(status || 302, {
'Location': map[url] || url
});
this.end();
};