Merge pull request #87 from koajs/original-url

this.originalUrl && this.request.originalUrl
This commit is contained in:
TJ Holowaychuk 2013-11-15 09:33:10 -08:00
commit 52307eeb72
5 changed files with 25 additions and 1 deletions

View file

@ -117,6 +117,7 @@ app.createContext = function(req, res){
request.ctx = response.ctx = context;
context.onerror = context.onerror.bind(context);
context.cookies = new Cookies(req, res);
context.originalUrl = request.originalUrl = req.url;
return context;
}

View file

@ -43,7 +43,6 @@ module.exports = {
* Delegate to Request#method.
*/
get method() {
return this.request.method;
},

View file

@ -18,4 +18,12 @@ describe('ctx.path=', function(){
ctx.path.should.equal('/logout');
ctx.url.should.equal('/logout?next=/dashboard');
})
it('should change .url but not .originalUrl', function(){
var ctx = context({ url: '/login' });
ctx.path = '/logout';
ctx.url.should.equal('/logout');
ctx.originalUrl.should.equal('/login');
ctx.request.originalUrl.should.equal('/login');
})
})

View file

@ -22,4 +22,12 @@ describe('ctx.query=', function(){
ctx.url.should.equal('/store/shoes?page=2&color=blue');
ctx.querystring.should.equal('page=2&color=blue');
})
it('should change .url but not .originalUrl', function(){
var ctx = context({ url: '/store/shoes' });
ctx.query = { page: 2 };
ctx.url.should.equal('/store/shoes?page=2');
ctx.originalUrl.should.equal('/store/shoes');
ctx.request.originalUrl.should.equal('/store/shoes');
})
})

View file

@ -8,4 +8,12 @@ describe('ctx.querystring=', function(){
ctx.url.should.equal('/store/shoes?page=2&color=blue');
ctx.querystring.should.equal('page=2&color=blue');
})
it('should change .url but not .originalUrl', function(){
var ctx = context({ url: '/store/shoes' });
ctx.querystring = 'page=2&color=blue';
ctx.url.should.equal('/store/shoes?page=2&color=blue');
ctx.originalUrl.should.equal('/store/shoes');
ctx.request.originalUrl.should.equal('/store/shoes');
})
})