Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
Merge pull request #101 from connor4312/96
Browse files Browse the repository at this point in the history
Swap out for deprecated hostname
  • Loading branch information
mattrobenolt committed Apr 16, 2015
2 parents e3b7750 + a4790f3 commit c33c024
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
4 changes: 2 additions & 2 deletions lib/parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || '<no host>';
var host = req.hostname || req.host || headers.host || '<no host>';

// protocol:
//
Expand Down
36 changes: 24 additions & 12 deletions test/raven.parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand All @@ -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'
};

Expand All @@ -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',
Expand Down Expand Up @@ -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' }
};
Expand All @@ -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',
};

Expand All @@ -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'
};
Expand All @@ -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'
Expand All @@ -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'
};

Expand All @@ -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'
};

Expand All @@ -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'
};
Expand All @@ -345,7 +357,7 @@ describe('raven.parsers', function(){
it('should fallback to <unavailable> if body is not available', function(){
var mockReq = {
method: 'GET',
host: 'mattrobenolt.com',
hostname: 'mattrobenolt.com',
url: '/some/path?key=value',
body: ''
};
Expand Down

0 comments on commit c33c024

Please sign in to comment.