Skip to content

Commit 0c72ca7

Browse files
colthreepvQard
authored andcommitted
chore(http): workaround(s) to suppress DEP0066 warnings (#1424)
1 parent ddfa91d commit 0c72ca7

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

lib/instrumentation/http-shared.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ function ensureUrl (v) {
108108
}
109109
}
110110

111+
function getSafeHost (res) {
112+
return res.getHeader ? res.getHeader('Host') : res._headers.host
113+
}
114+
111115
exports.traceOutgoingRequest = function (agent, moduleName, method) {
112116
var spanType = 'ext.' + moduleName + '.http'
113117
var ins = agent._instrumentation
@@ -146,17 +150,17 @@ exports.traceOutgoingRequest = function (agent, moduleName, method) {
146150
var req = orig.apply(this, newArgs)
147151
if (!span) return req
148152

149-
if (req._headers.host === agent._conf.serverHost) {
153+
if (getSafeHost(req) === agent._conf.serverHost) {
150154
agent.logger.debug('ignore %s request to intake API %o', moduleName, { id: id })
151155
return req
152156
} else {
153157
var protocol = req.agent && req.agent.protocol
154-
agent.logger.debug('request details: %o', { protocol: protocol, host: req._headers.host, id: id })
158+
agent.logger.debug('request details: %o', { protocol: protocol, host: getSafeHost(req), id: id })
155159
}
156160

157161
ins.bindEmitter(req)
158162

159-
span.name = req.method + ' ' + req._headers.host + parsers.parseUrl(req.path).pathname
163+
span.name = req.method + ' ' + getSafeHost(req) + parsers.parseUrl(req.path).pathname
160164

161165
// TODO: Research if it's possible to add this to the prototype instead.
162166
// Or if it's somehow preferable to listen for when a `response` listener

lib/instrumentation/modules/http.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ var semver = require('semver')
55
var httpShared = require('../http-shared')
66
var shimmer = require('../shimmer')
77

8+
function getSafeHeaders (res) {
9+
return res.getHeaders ? res.getHeaders() : res._headers
10+
}
11+
812
module.exports = function (http, agent, { enabled }) {
913
if (!enabled) return http
1014
agent.logger.debug('shimming http.Server.prototype.emit function')
@@ -26,7 +30,7 @@ module.exports = function (http, agent, { enabled }) {
2630
function wrapWriteHead (original) {
2731
return function wrappedWriteHead () {
2832
var headers = arguments.length === 1
29-
? this._headers // might be because of implicit headers.
33+
? getSafeHeaders(this) // might be because of implicit headers.
3034
: arguments[arguments.length - 1]
3135

3236
var result = original.apply(this, arguments)

0 commit comments

Comments
 (0)