Skip to content

Commit 0acfd39

Browse files
committed
But don't break 3.x compatibility
1 parent 36417aa commit 0acfd39

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/parsers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ module.exports.parseRequest = function parseRequest(req, kwargs) {
7878
// host:
7979
//
8080
// node: req.headers.host
81-
// express: req.hostname
81+
// express: req.hostname in > 4 and req.host in < 4
8282
// koa: req.host
8383
//
84-
var host = req.hostname || headers.host || '<no host>';
84+
var host = req.host || req.hostname || headers.host || '<no host>';
8585

8686
// protocol:
8787
//

test/raven.parsers.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,18 @@ describe('raven.parsers', function(){
113113
parsed['request'].url.should.equal('http://mattrobenolt.com/some/path?key=value');
114114
});
115115

116+
it('should detect host via deprecated `req.host`', function(){
117+
var mockReq = {
118+
method: 'GET',
119+
host: 'mattrobenolt.com',
120+
url: '/some/path?key=value'
121+
};
122+
123+
var parsed = raven.parsers.parseRequest(mockReq);
124+
125+
parsed['request'].url.should.equal('http://mattrobenolt.com/some/path?key=value');
126+
});
127+
116128
it('should detect host via `req.header.host`', function(){
117129
var mockReq = {
118130
method: 'GET',

0 commit comments

Comments
 (0)