From 18c2cd1dacbd332a0fa7def61cc8d61bb2c59f50 Mon Sep 17 00:00:00 2001 From: Jonathan Ong Date: Thu, 14 Nov 2013 14:18:05 -0800 Subject: [PATCH] this.originalUrl && this.request.originalUrl --- lib/application.js | 1 + lib/context.js | 1 - test/request/path.js | 8 ++++++++ test/request/query.js | 8 ++++++++ test/request/querystring.js | 8 ++++++++ 5 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/application.js b/lib/application.js index b21c30c..db7cf6e 100644 --- a/lib/application.js +++ b/lib/application.js @@ -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; } diff --git a/lib/context.js b/lib/context.js index 3fc740b..5485ac2 100644 --- a/lib/context.js +++ b/lib/context.js @@ -43,7 +43,6 @@ module.exports = { * Delegate to Request#method. */ - get method() { return this.request.method; }, diff --git a/test/request/path.js b/test/request/path.js index 0001cf5..8f9e6ae 100644 --- a/test/request/path.js +++ b/test/request/path.js @@ -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'); + }) }) \ No newline at end of file diff --git a/test/request/query.js b/test/request/query.js index 3c4d448..31a76b3 100644 --- a/test/request/query.js +++ b/test/request/query.js @@ -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'); + }) }) \ No newline at end of file diff --git a/test/request/querystring.js b/test/request/querystring.js index 85d1ce4..53a4a20 100644 --- a/test/request/querystring.js +++ b/test/request/querystring.js @@ -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'); + }) }) \ No newline at end of file