From 5d8556aba2682c8add539a77a8b8f35ae3116797 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Og=C3=B3rek?= Date: Thu, 5 Oct 2017 13:59:03 +0200 Subject: [PATCH] fix: attach remaining non-enumerables to req --- lib/client.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/client.js b/lib/client.js index 087cc88..c2acda5 100644 --- a/lib/client.js +++ b/lib/client.js @@ -526,19 +526,30 @@ extend(Raven.prototype, { * (eg. globalContext.request + domainContext.request + kwargs.request), * we manually pull them out from original objects. * + * Same scenario happens when some frameworks (eg. Koa) decide to use request within + * request. eg `this.request.req`, which adds aliases to the main `request` object. + * By manually reassigning them here, we don't need to add additional checks + * like `req.method || (req.req && req.req.method)` + * * We don't use Object.assign/extend as it's only merging over objects own properties, * and we don't want to go through all of the properties as well, as we simply don't * need all of them. - * - * So far the only missing piece is `ip`, but we can specify what properties should - * be pulled by extending `nonEnumerables` array. **/ var sources = Array.from(arguments).filter(function(source) { return Object.prototype.toString.call(source) === '[object Object]'; }); sources = [{}].concat(sources); var request = extend.apply(null, sources); - var nonEnumberables = ['ip']; + var nonEnumberables = [ + 'headers', + 'host', + 'ip', + 'method', + 'protocol', + 'query', + 'secure', + 'url' + ]; nonEnumberables.forEach(function(key) { sources.forEach(function(source) {