Skip to content

Commit 9fe3ea6

Browse files
author
Rui Marinho
committed
Add comments about where the information is coming
1 parent fffe8bf commit 9fe3ea6

File tree

2 files changed

+83
-10
lines changed

2 files changed

+83
-10
lines changed

lib/parsers.js

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,36 +58,81 @@ module.exports.parseQuery = function parseQuery(query, engine, kwargs) {
5858
module.exports.parseRequest = function parseRequest(req, kwargs) {
5959
kwargs = kwargs || {};
6060

61-
// headers
61+
// headers:
62+
//
63+
// node: req.headers
64+
// express: req.header
65+
// koa: req.header
66+
//
6267
var headers = req.header || req.headers || {};
6368

64-
// method
69+
// method:
70+
//
71+
// node: req.method
72+
// express: req.method
73+
// koa: req.method
74+
//
6575
var method = req.method;
6676

67-
// host
77+
// host:
78+
//
79+
// node: req.headers.host
80+
// express: req.host
81+
// koa: req.host
82+
//
6883
var host = req.host || headers.host || '<no host>';
6984

70-
// protocol
85+
// protocol:
86+
//
87+
// node: <n/a>
88+
// express: req.protocol
89+
// koa: req.protocol
90+
//
7191
var protocol = ('https' === req.protocol || true === req.secure || true === (req.socket || {}).encrypted ||
7292
('https' === (headers['x-forwarded-proto'] || '').split(/\s*,\s*/)[0])) ||
73-
(443 === Number(headers['x-forwarded-port'] || '')) ? 'https' : 'http';
93+
('443' === headers['x-forwarded-port'] || '') ? 'https' : 'http';
7494

75-
// url (including path and query string)
76-
var originalUrl = req.url;
95+
// url (including path and query string):
96+
//
97+
// node: req.originalUrl
98+
// express: req.originalUrl
99+
// koa: req.url
100+
//
101+
var originalUrl = req.originalUrl || req.url;
77102

78103
// absolute url
79104
var url = protocol + '://' + host + originalUrl;
80105

81106
// query string
107+
//
108+
// node: req.url (raw)
109+
// express: req.query
110+
// koa: req.query
111+
//
82112
var query = req.query || urlParser.parse(originalUrl || '', true).query;
83113

84-
// cookies
114+
// cookies:
115+
//
116+
// node: req.headers.cookie
117+
// express: req.cookies (expressjs/cookies)
118+
// koa: req.headers.cookie
119+
//
85120
var cookies = (isPlainObject(req.cookies) ? req.cookies : '' ) || cookie.parse(headers.cookie || headers.cookies || '');
86121

87-
// body data
122+
// body data:
123+
//
124+
// node: req.body
125+
// express: req.body
126+
// koa: req.body
127+
//
88128
var data = req.body || '<unavailable>';
89129

90-
// client ip
130+
// client ip:
131+
//
132+
// node: req.connection.remoteAddress
133+
// express: req.ip
134+
// koa: req.ip
135+
//
91136
var ip = req.ip || (headers['x-forwarded-for'] || '').split(/\s*,\s*/)[0] || (req.connection || {}).remoteAddress;
92137

93138
// http interface

test/raven.parsers.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,34 @@ describe('raven.parsers', function(){
387387
});
388388
});
389389

390+
describe('`url` detection', function() {
391+
it('should detect url via `req.originalUrl`', function(){
392+
var mockReq = {
393+
method: 'GET',
394+
protocol: 'https',
395+
host: 'mattrobenolt.com',
396+
originalUrl: '/some/path?key=value'
397+
};
398+
399+
var parsed = raven.parsers.parseRequest(mockReq);
400+
401+
parsed['sentry.interfaces.Http'].url.should.equal('https://mattrobenolt.com/some/path?key=value');
402+
});
403+
404+
it('should detect url via `req.url`', function(){
405+
var mockReq = {
406+
method: 'GET',
407+
protocol: 'https',
408+
host: 'mattrobenolt.com',
409+
url: '/some/path?key=value'
410+
};
411+
412+
var parsed = raven.parsers.parseRequest(mockReq);
413+
414+
parsed['sentry.interfaces.Http'].url.should.equal('https://mattrobenolt.com/some/path?key=value');
415+
});
416+
});
417+
390418
describe('`body` detection', function() {
391419
it('should detect body via `req.body`', function(){
392420
var mockReq = {

0 commit comments

Comments
 (0)