Skip to content

Commit c33c024

Browse files
committed
Merge pull request #101 from connor4312/96
Swap out for deprecated hostname
2 parents e3b7750 + a4790f3 commit c33c024

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
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.host
81+
// express: req.hostname in > 4 and req.host in < 4
8282
// koa: req.host
8383
//
84-
var host = req.host || headers.host || '<no host>';
84+
var host = req.hostname || req.host || headers.host || '<no host>';
8585

8686
// protocol:
8787
//

test/raven.parsers.js

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describe('raven.parsers', function(){
5858
it('should detect headers via `req.headers`', function(){
5959
var mockReq = {
6060
method: 'GET',
61-
host: 'mattrobenolt.com',
61+
hostname: 'mattrobenolt.com',
6262
url: '/some/path?key=value',
6363
headers: {
6464
foo: 'bar'
@@ -73,7 +73,7 @@ describe('raven.parsers', function(){
7373
it('should detect headers via `req.header`', function(){
7474
var mockReq = {
7575
method: 'GET',
76-
host: 'mattrobenolt.com',
76+
hostname: 'mattrobenolt.com',
7777
url: '/some/path?key=value',
7878
header: {
7979
foo: 'bar'
@@ -90,7 +90,7 @@ describe('raven.parsers', function(){
9090
it('should detect method via `req.method`', function(){
9191
var mockReq = {
9292
method: 'GET',
93-
host: 'mattrobenolt.com',
93+
hostname: 'mattrobenolt.com',
9494
url: '/some/path?key=value'
9595
};
9696

@@ -101,7 +101,19 @@ describe('raven.parsers', function(){
101101
});
102102

103103
describe('`host` detection', function() {
104-
it('should detect host via `req.host`', function(){
104+
it('should detect host via `req.hostname`', function(){
105+
var mockReq = {
106+
method: 'GET',
107+
hostname: 'mattrobenolt.com',
108+
url: '/some/path?key=value'
109+
};
110+
111+
var parsed = raven.parsers.parseRequest(mockReq);
112+
113+
parsed['request'].url.should.equal('http://mattrobenolt.com/some/path?key=value');
114+
});
115+
116+
it('should detect host via deprecated `req.host`', function(){
105117
var mockReq = {
106118
method: 'GET',
107119
host: 'mattrobenolt.com',
@@ -243,7 +255,7 @@ describe('raven.parsers', function(){
243255
it('should detect query via `req.query`', function(){
244256
var mockReq = {
245257
method: 'GET',
246-
host: 'mattrobenolt.com',
258+
hostname: 'mattrobenolt.com',
247259
url: '/some/path?key=value',
248260
query: { some: 'key' }
249261
};
@@ -256,7 +268,7 @@ describe('raven.parsers', function(){
256268
it('should detect query via `req.url`', function(){
257269
var mockReq = {
258270
method: 'GET',
259-
host: 'mattrobenolt.com',
271+
hostname: 'mattrobenolt.com',
260272
url: '/some/path?foo=bar',
261273
};
262274

@@ -272,7 +284,7 @@ describe('raven.parsers', function(){
272284
method: 'GET',
273285
url: '/some/path?key=value',
274286
headers: {
275-
host: 'mattrobenolt.com',
287+
hostname: 'mattrobenolt.com',
276288
},
277289
ip: '69.69.69.69'
278290
};
@@ -287,7 +299,7 @@ describe('raven.parsers', function(){
287299
method: 'GET',
288300
url: '/some/path?key=value',
289301
headers: {
290-
host: 'mattrobenolt.com',
302+
hostname: 'mattrobenolt.com',
291303
},
292304
connection: {
293305
remoteAddress: '69.69.69.69'
@@ -305,7 +317,7 @@ describe('raven.parsers', function(){
305317
var mockReq = {
306318
method: 'GET',
307319
protocol: 'https',
308-
host: 'mattrobenolt.com',
320+
hostname: 'mattrobenolt.com',
309321
originalUrl: '/some/path?key=value'
310322
};
311323

@@ -318,7 +330,7 @@ describe('raven.parsers', function(){
318330
var mockReq = {
319331
method: 'GET',
320332
protocol: 'https',
321-
host: 'mattrobenolt.com',
333+
hostname: 'mattrobenolt.com',
322334
url: '/some/path?key=value'
323335
};
324336

@@ -332,7 +344,7 @@ describe('raven.parsers', function(){
332344
it('should detect body via `req.body`', function(){
333345
var mockReq = {
334346
method: 'GET',
335-
host: 'mattrobenolt.com',
347+
hostname: 'mattrobenolt.com',
336348
url: '/some/path?key=value',
337349
body: 'foo=bar'
338350
};
@@ -345,7 +357,7 @@ describe('raven.parsers', function(){
345357
it('should fallback to <unavailable> if body is not available', function(){
346358
var mockReq = {
347359
method: 'GET',
348-
host: 'mattrobenolt.com',
360+
hostname: 'mattrobenolt.com',
349361
url: '/some/path?key=value',
350362
body: ''
351363
};

0 commit comments

Comments
 (0)