Skip to content

Commit 5422246

Browse files
authored
Drop process.env, pass IP as User interface (refs #58, #169, #170) (#181)
1 parent 14401a2 commit 5422246

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

lib/parsers.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,9 @@ module.exports.parseRequest = function parseRequest(req, kwargs) {
156156
headers: headers,
157157
cookies: cookies,
158158
data: data,
159-
url: url,
160-
env: process.env
159+
url: url
161160
};
162161

163-
// add remote ip
164-
http.env.REMOTE_ADDR = ip;
165-
166162
// expose http interface
167163
kwargs.request = http;
168164

@@ -171,12 +167,14 @@ module.exports.parseRequest = function parseRequest(req, kwargs) {
171167
// typically found on req.user according to Express and Passport
172168

173169
var user = {};
174-
if (req.user && !kwargs.user) {
175-
// shallow copy is okay because we are only modifying top-level
176-
// object (req.user)
177-
for (var key in req.user) {
178-
if ({}.hasOwnProperty.call(req.user, key)) {
179-
user[key] = req.user[key];
170+
if (!kwargs.user) {
171+
if (req.user) {
172+
// shallow copy is okay because we are only modifying top-level
173+
// object (req.user)
174+
for (var key in req.user) {
175+
if ({}.hasOwnProperty.call(req.user, key)) {
176+
user[key] = req.user[key];
177+
}
180178
}
181179
}
182180

test/raven.parsers.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ describe('raven.parsers', function() {
5353
var parsed = raven.parsers.parseRequest(mockReq);
5454
parsed.should.have.property('request');
5555
parsed.request.url.should.equal('https://mattrobenolt.com/some/path?key=value');
56-
parsed.request.env.NODE_ENV.should.equal(process.env.NODE_ENV);
57-
parsed.request.env.REMOTE_ADDR.should.equal('127.0.0.1');
56+
parsed.user.ip_address.should.equal('127.0.0.1');
5857
});
5958

6059
describe('`headers` detection', function() {
@@ -308,7 +307,7 @@ describe('raven.parsers', function() {
308307

309308
var parsed = raven.parsers.parseRequest(mockReq);
310309

311-
parsed.request.env.REMOTE_ADDR.should.equal('127.0.0.1');
310+
parsed.user.ip_address.should.equal('127.0.0.1');
312311
});
313312

314313
it('should detect ip via `req.connection.remoteAddress`', function() {
@@ -325,7 +324,7 @@ describe('raven.parsers', function() {
325324

326325
var parsed = raven.parsers.parseRequest(mockReq);
327326

328-
parsed.request.env.REMOTE_ADDR.should.equal('127.0.0.1');
327+
parsed.user.ip_address.should.equal('127.0.0.1');
329328
});
330329
});
331330

0 commit comments

Comments
 (0)