diff --git a/lib/parsers.js b/lib/parsers.js index 3f23aed..68d679e 100644 --- a/lib/parsers.js +++ b/lib/parsers.js @@ -78,10 +78,10 @@ module.exports.parseRequest = function parseRequest(req, kwargs) { // host: // // node: req.headers.host - // express: req.host + // express: req.hostname in > 4 and req.host in < 4 // koa: req.host // - var host = req.host || headers.host || ''; + var host = req.hostname || req.host || headers.host || ''; // protocol: // diff --git a/test/raven.parsers.js b/test/raven.parsers.js index c272372..da4f2ea 100644 --- a/test/raven.parsers.js +++ b/test/raven.parsers.js @@ -58,7 +58,7 @@ describe('raven.parsers', function(){ it('should detect headers via `req.headers`', function(){ var mockReq = { method: 'GET', - host: 'mattrobenolt.com', + hostname: 'mattrobenolt.com', url: '/some/path?key=value', headers: { foo: 'bar' @@ -73,7 +73,7 @@ describe('raven.parsers', function(){ it('should detect headers via `req.header`', function(){ var mockReq = { method: 'GET', - host: 'mattrobenolt.com', + hostname: 'mattrobenolt.com', url: '/some/path?key=value', header: { foo: 'bar' @@ -90,7 +90,7 @@ describe('raven.parsers', function(){ it('should detect method via `req.method`', function(){ var mockReq = { method: 'GET', - host: 'mattrobenolt.com', + hostname: 'mattrobenolt.com', url: '/some/path?key=value' }; @@ -101,7 +101,19 @@ describe('raven.parsers', function(){ }); describe('`host` detection', function() { - it('should detect host via `req.host`', function(){ + it('should detect host via `req.hostname`', function(){ + var mockReq = { + method: 'GET', + hostname: 'mattrobenolt.com', + url: '/some/path?key=value' + }; + + var parsed = raven.parsers.parseRequest(mockReq); + + parsed['request'].url.should.equal('http://mattrobenolt.com/some/path?key=value'); + }); + + it('should detect host via deprecated `req.host`', function(){ var mockReq = { method: 'GET', host: 'mattrobenolt.com', @@ -243,7 +255,7 @@ describe('raven.parsers', function(){ it('should detect query via `req.query`', function(){ var mockReq = { method: 'GET', - host: 'mattrobenolt.com', + hostname: 'mattrobenolt.com', url: '/some/path?key=value', query: { some: 'key' } }; @@ -256,7 +268,7 @@ describe('raven.parsers', function(){ it('should detect query via `req.url`', function(){ var mockReq = { method: 'GET', - host: 'mattrobenolt.com', + hostname: 'mattrobenolt.com', url: '/some/path?foo=bar', }; @@ -272,7 +284,7 @@ describe('raven.parsers', function(){ method: 'GET', url: '/some/path?key=value', headers: { - host: 'mattrobenolt.com', + hostname: 'mattrobenolt.com', }, ip: '69.69.69.69' }; @@ -287,7 +299,7 @@ describe('raven.parsers', function(){ method: 'GET', url: '/some/path?key=value', headers: { - host: 'mattrobenolt.com', + hostname: 'mattrobenolt.com', }, connection: { remoteAddress: '69.69.69.69' @@ -305,7 +317,7 @@ describe('raven.parsers', function(){ var mockReq = { method: 'GET', protocol: 'https', - host: 'mattrobenolt.com', + hostname: 'mattrobenolt.com', originalUrl: '/some/path?key=value' }; @@ -318,7 +330,7 @@ describe('raven.parsers', function(){ var mockReq = { method: 'GET', protocol: 'https', - host: 'mattrobenolt.com', + hostname: 'mattrobenolt.com', url: '/some/path?key=value' }; @@ -332,7 +344,7 @@ describe('raven.parsers', function(){ it('should detect body via `req.body`', function(){ var mockReq = { method: 'GET', - host: 'mattrobenolt.com', + hostname: 'mattrobenolt.com', url: '/some/path?key=value', body: 'foo=bar' }; @@ -345,7 +357,7 @@ describe('raven.parsers', function(){ it('should fallback to if body is not available', function(){ var mockReq = { method: 'GET', - host: 'mattrobenolt.com', + hostname: 'mattrobenolt.com', url: '/some/path?key=value', body: '' };