From 72a47fb92f589994f8c8210bf36e88aeaea15f0e Mon Sep 17 00:00:00 2001 From: Connor Peet Date: Tue, 2 Dec 2014 19:27:53 -0500 Subject: [PATCH 1/4] Swap out for deprecated hostname --- lib/parsers.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/parsers.js b/lib/parsers.js index 38a108e..e447525 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 // koa: req.host // - var host = req.host || headers.host || ''; + var host = req.hostname || headers.host || ''; // protocol: // From 36417aae521062eb9dcac26dc6caea14f4a2b150 Mon Sep 17 00:00:00 2001 From: Connor Peet Date: Tue, 2 Dec 2014 19:30:46 -0500 Subject: [PATCH 2/4] Update tests --- test/raven.parsers.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/test/raven.parsers.js b/test/raven.parsers.js index 78f9c7f..90a6740 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,10 +101,10 @@ 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', - host: 'mattrobenolt.com', + hostname: 'mattrobenolt.com', url: '/some/path?key=value' }; @@ -243,7 +243,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 +256,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 +272,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 +287,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 +305,7 @@ describe('raven.parsers', function(){ var mockReq = { method: 'GET', protocol: 'https', - host: 'mattrobenolt.com', + hostname: 'mattrobenolt.com', originalUrl: '/some/path?key=value' }; @@ -318,7 +318,7 @@ describe('raven.parsers', function(){ var mockReq = { method: 'GET', protocol: 'https', - host: 'mattrobenolt.com', + hostname: 'mattrobenolt.com', url: '/some/path?key=value' }; @@ -332,7 +332,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 +345,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: '' }; From 0acfd398f417c45741497e6647037889ecb78072 Mon Sep 17 00:00:00 2001 From: Connor Peet Date: Tue, 2 Dec 2014 19:32:42 -0500 Subject: [PATCH 3/4] But don't break 3.x compatibility --- lib/parsers.js | 4 ++-- test/raven.parsers.js | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/parsers.js b/lib/parsers.js index e447525..2017b37 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.hostname + // express: req.hostname in > 4 and req.host in < 4 // koa: req.host // - var host = req.hostname || headers.host || ''; + var host = req.host || req.hostname || headers.host || ''; // protocol: // diff --git a/test/raven.parsers.js b/test/raven.parsers.js index 90a6740..754a6be 100644 --- a/test/raven.parsers.js +++ b/test/raven.parsers.js @@ -113,6 +113,18 @@ describe('raven.parsers', function(){ 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', + 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 `req.header.host`', function(){ var mockReq = { method: 'GET', From a4790f322c870f4f072fcf914e77c59e3a65287f Mon Sep 17 00:00:00 2001 From: Connor Peet Date: Wed, 3 Dec 2014 09:33:39 -0500 Subject: [PATCH 4/4] Try to get hostname first --- lib/parsers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/parsers.js b/lib/parsers.js index 2017b37..cf08fda 100644 --- a/lib/parsers.js +++ b/lib/parsers.js @@ -81,7 +81,7 @@ module.exports.parseRequest = function parseRequest(req, kwargs) { // express: req.hostname in > 4 and req.host in < 4 // koa: req.host // - var host = req.host || req.hostname || headers.host || ''; + var host = req.hostname || req.host || headers.host || ''; // protocol: //