Superagent: Deprecation Warning when accessing headers

Created on 31 Jul 2019  路  4Comments  路  Source: visionmedia/superagent

bug: (node:52579) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated is shown when res.request parameters are accessed

test case:

$ node
Welcome to Node.js v12.6.0.
Type ".help" for more information.
> const request = require('superagent')
undefined
> (async () => { const res = await request.agent().get('https://google.com'); console.log(res.request.url) })()
Promise { <pending> }
> (node:52579) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated
https://www.google.com/

possible fix
https://github.com/BrowserSync/browser-sync/pull/1698/files

extra info
https://github.com/villadora/express-http-proxy/issues/413

Most helpful comment

v5.1.2 is released to npm and everything should be fine with latest versions of Node now 馃帀

If you find any further deprecation warnings in the future please let me know!

npm install superagent@latest

or with yarn:

yarn add superagent@latest

https://github.com/visionmedia/superagent/releases/tag/v5.1.2

All 4 comments

In my own debugging the warning is caused by Request#_redirect which calls cleanHeader with a reference to req._headers.

It looks like this method and the helper function grab a reference to the internal collection of headers and delete some of them, then use this object to update the internal header values in Request. Node's own Request / OutgoingMessage doesn't have a bulk update method so normally this wouldn't work but I guess the Superagent mock version can still do it, so even though getHeaders gives you a shallow copy, it should be OK. Maybe? You'd have to grab the copy once (as in the PR from @ad-m ) and pass it to cleanHeader instead of referring to _headers again, and I'm not familiar enough with the codebase to say whether there are side effects since the old code deletes the headers in the actual Request while the new method will only delete from the shallow copy.

Any update on this?

v5.1.2 is released to npm and everything should be fine with latest versions of Node now 馃帀

If you find any further deprecation warnings in the future please let me know!

npm install superagent@latest

or with yarn:

yarn add superagent@latest

https://github.com/visionmedia/superagent/releases/tag/v5.1.2

thanks @niftylettuce @ad-m and everyone who helped out along the way 馃憦馃檹馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kornelski picture kornelski  路  4Comments

mikecousins picture mikecousins  路  6Comments

littlee picture littlee  路  8Comments

ropez picture ropez  路  7Comments

srohde picture srohde  路  8Comments