Skip to content

Commit 029bfdc

Browse files
author
Rui Marinho
committed
Add HTTPS detection via X-Forwarded-Proto
1 parent d82bc76 commit 029bfdc

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/parsers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ module.exports.parseRequest = function parseRequest(req, kwargs) {
5858

5959
// create absolute url
6060
var host = req.headers.host || '<no host>';
61-
var full_url = (req.socket.encrypted ? 'https' : 'http') + '://' + host + req.url;
61+
var full_url = (req.socket.encrypted || 'https' === req.headers['x-forwarded-proto'] ? 'https' : 'http') + '://' + host + req.url;
6262

6363
var http = {
6464
method: req.method,

test/raven.parsers.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,27 @@ describe('raven.parsers', function(){
5252
parsed['sentry.interfaces.Http'].env.NODE_ENV.should.equal(process.env.NODE_ENV);
5353
parsed['sentry.interfaces.Http'].env.REMOTE_ADDR.should.equal('69.69.69.69');
5454
});
55+
56+
it('should detect https via `x-forwarded-proto`', function(){
57+
var mockReq = {
58+
method: 'GET',
59+
url: '/some/path?key=value',
60+
headers: {
61+
host: 'mattrobenolt.com',
62+
'x-forwarded-proto': 'https'
63+
},
64+
body: '',
65+
cookies: {},
66+
socket: {
67+
encrypted: false
68+
},
69+
connection: {
70+
remoteAddress: '69.69.69.69'
71+
}
72+
};
73+
var parsed = raven.parsers.parseRequest(mockReq);
74+
parsed['sentry.interfaces.Http'].url.should.equal('https://mattrobenolt.com/some/path?key=value');
75+
});
5576
});
5677

5778
describe('#parseError()', function(){

0 commit comments

Comments
 (0)