Skip to content

Commit 5d50f47

Browse files
committed
Merge pull request #79 from seegno/feature/request-feature-detection
Add request feature detection
2 parents 64f9124 + 9eb6b81 commit 5d50f47

File tree

3 files changed

+412
-47
lines changed

3 files changed

+412
-47
lines changed

lib/parsers.js

Lines changed: 94 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
var utils = require('./utils');
2-
var url = require('url');
31
var cookie = require('cookie');
2+
var urlParser = require('url');
3+
var utils = require('./utils');
44

55
module.exports.parseText = function parseText(message, kwargs) {
66
kwargs = kwargs || {};
7-
kwargs['message'] = message;
7+
kwargs.message = message;
8+
89
return kwargs;
910
};
1011

1112
module.exports.parseError = function parseError(err, kwargs, cb) {
1213
utils.parseStack(err, function(frames) {
13-
kwargs['message'] = err.name + ': ' + (err.message || '<no message>');
14+
kwargs.message = err.name + ': ' + (err.message || '<no message>');
1415
kwargs['sentry.interfaces.Exception'] = {
1516
type: err.name,
1617
value:err.message
@@ -28,13 +29,13 @@ module.exports.parseError = function parseError(err, kwargs, cb) {
2829
}
2930
}
3031
if (extraErrorProps) {
31-
kwargs['extra'] = kwargs['extra'] || {};
32-
kwargs['extra'][err.name] = extraErrorProps;
32+
kwargs.extra = kwargs.extra || {};
33+
kwargs.extra[err.name] = extraErrorProps;
3334
}
3435

3536
for (var n = frames.length - 1; n >= 0; n--) {
3637
if (frames[n].in_app) {
37-
kwargs['culprit'] = utils.getCulprit(frames[n]);
38+
kwargs.culprit = utils.getCulprit(frames[n]);
3839
break;
3940
}
4041
}
@@ -45,7 +46,7 @@ module.exports.parseError = function parseError(err, kwargs, cb) {
4546

4647
module.exports.parseQuery = function parseQuery(query, engine, kwargs) {
4748
kwargs = kwargs || {};
48-
kwargs['message'] = query;
49+
kwargs.message = query;
4950
kwargs['sentry.interfaces.Query'] = {
5051
query: query,
5152
engine: engine
@@ -56,23 +57,97 @@ module.exports.parseQuery = function parseQuery(query, engine, kwargs) {
5657
module.exports.parseRequest = function parseRequest(req, kwargs) {
5758
kwargs = kwargs || {};
5859

59-
// create absolute url
60-
var host = req.headers.host || '<no host>';
61-
var full_url = (req.socket.encrypted || 'https' === req.headers['x-forwarded-proto'] ? 'https' : 'http') + '://' + host + req.url;
60+
// headers:
61+
//
62+
// node: req.headers
63+
// express: req.headers
64+
// koa: req.header
65+
//
66+
var headers = req.headers || req.header || {};
67+
68+
// method:
69+
//
70+
// node: req.method
71+
// express: req.method
72+
// koa: req.method
73+
//
74+
var method = req.method;
75+
76+
// host:
77+
//
78+
// node: req.headers.host
79+
// express: req.host
80+
// koa: req.host
81+
//
82+
var host = req.host || headers.host || '<no host>';
83+
84+
// protocol:
85+
//
86+
// node: <n/a>
87+
// express: req.protocol
88+
// koa: req.protocol
89+
//
90+
var protocol = ('https' === req.protocol || true === req.secure || true === (req.socket || {}).encrypted) ? 'https' : 'http';
91+
92+
// url (including path and query string):
93+
//
94+
// node: req.originalUrl
95+
// express: req.originalUrl
96+
// koa: req.url
97+
//
98+
var originalUrl = req.originalUrl || req.url;
6299

100+
// absolute url
101+
var url = protocol + '://' + host + originalUrl;
102+
103+
// query string
104+
//
105+
// node: req.url (raw)
106+
// express: req.query
107+
// koa: req.query
108+
//
109+
var query = req.query || urlParser.parse(originalUrl || '', true).query;
110+
111+
// cookies:
112+
//
113+
// node: req.headers.cookie
114+
// express: req.headers.cookie
115+
// koa: req.headers.cookie
116+
//
117+
var cookies = cookie.parse(headers.cookie || '');
118+
119+
// body data:
120+
//
121+
// node: req.body
122+
// express: req.body
123+
// koa: req.body
124+
//
125+
var data = req.body || '<unavailable>';
126+
127+
// client ip:
128+
//
129+
// node: req.connection.remoteAddress
130+
// express: req.ip
131+
// koa: req.ip
132+
//
133+
var ip = req.ip || (req.connection || {}).remoteAddress;
134+
135+
// http interface
63136
var http = {
64-
method: req.method,
65-
query_string: url.parse(req.url).query,
66-
headers: req.headers,
67-
cookies: req.cookies || cookie.parse(req.headers.cookies || ''),
68-
data: req.body || '<unavailable>',
69-
url: full_url,
137+
method: method,
138+
query_string: query,
139+
headers: headers,
140+
cookies: cookies,
141+
data: data,
142+
url: url,
70143
env: process.env
71144
};
72145

73-
var ip = (req.headers['x-forwarded-for'] || '').split(',')[0] ||
74-
req.connection.remoteAddress;
146+
// add remote ip
75147
http.env.REMOTE_ADDR = ip;
148+
149+
// expose http interface
76150
kwargs['sentry.interfaces.Http'] = http;
151+
77152
return kwargs;
78153
};

package.json

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
{
22
"name": "raven",
33
"description": "A standalone (Node.js) client for Sentry",
4-
"keywords": ["raven", "sentry", "python", "errors", "debugging", "exceptions"],
4+
"keywords": [
5+
"raven",
6+
"sentry",
7+
"python",
8+
"errors",
9+
"debugging",
10+
"exceptions"
11+
],
512
"version": "0.6.3",
613
"repository": "git://github.com/getsentry/raven-node.git",
714
"author": "Matt Robenolt <[email protected]>",
@@ -17,21 +24,22 @@
1724
"node": ">= 0.6.0"
1825
},
1926
"dependencies": {
20-
"node-uuid": "~1.4.1",
21-
"stack-trace": "0.0.7",
27+
"cookie": "0.1.0",
2228
"lsmod": "~0.0.3",
23-
"cookie": "0.1.0"
29+
"node-uuid": "~1.4.1",
30+
"stack-trace": "0.0.7"
2431
},
2532
"devDependencies": {
26-
"mocha": "*",
27-
"should": "~3.3.1",
28-
"nock": "*",
33+
"coffee-script": "~1.7.1",
2934
"glob": "*",
35+
"mocha": "*",
3036
"mock-udp": "*",
31-
"coffee-script": "~1.7.1"
37+
"nock": "*",
38+
"should": "~3.3.1"
3239
},
3340
"optionalDependencies": {
3441
"connect": "*",
35-
"express": "*"
42+
"express": "*",
43+
"koa": "*"
3644
}
3745
}

0 commit comments

Comments
 (0)