Skip to content

Commit

Permalink
location: back override option
Browse files Browse the repository at this point in the history
Added tests for res.location('back')
Made option to turn off built 'back' referrer functionality when not
working the way it was expected.

fixes: #3290
  • Loading branch information
WORMSS committed May 11, 2017
1 parent a13938e commit 28d27b2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ app.defaultConfiguration = function defaultConfiguration() {

// default settings
this.enable('x-powered-by');
this.enable('location back-referrer');
this.set('etag', 'weak');
this.set('env', env);
this.set('query parser', 'extended');
Expand Down
2 changes: 1 addition & 1 deletion lib/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ res.location = function location(url) {
var loc = url;

// "back" is an alias for the referrer
if (url === 'back') {
if (url === 'back' && this.app.enabled('location back-referrer')) {
loc = this.req.get('Referrer') || '/';
}

Expand Down
15 changes: 15 additions & 0 deletions test/res.location.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,21 @@ describe('res', function(){
.expect('Location', '/')
.expect(200, done)
})

it('should set the header to "back" on back', function (done) {
var app = express()

app.disable("location back-referrer")

app.use(function (req, res) {
res.location('back').end()
})

request(app)
.get('/')
.expect('Location', 'back')
.expect(200, done)
})
})
})
})

0 comments on commit 28d27b2

Please sign in to comment.