Breaking expected Node behaviour for http.get
See original GitHub issueRelated: https://github.com/nock/nock/pull/1588 and https://github.com/newrelic/node-newrelic/issues/316
New Relic (https://github.com/newrelic/node-newrelic) is overwriting http.get and http.request like you do in https://github.com/mastermatt/nock/blob/master/lib/common.js#L102. But when http.get is calling http.request like here, a call to http.get will call http.request twice when using nock in a New Relic test.
To prove that this is not native Node behaviour (at least on Node 12):
const http = require('http');
function request() {
console.log('http.request', arguments);
}
http.request = request;
// our request function is not called
http.get('http://google.com', () => {});
Looks like this change in https://github.com/mastermatt/nock/blob/3fbc69d74f6d23b33c2c6b144aa9fbf1d855cd18/lib/common.js#L102-L104 works:
const req = newRequest(proto, overriddenGet.bind(module), [
input,
options,
callback,
])
req.end()
return req
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:8 (5 by maintainers)
Top Results From Across the Web
HTTP/1 request destroy behavior change on framing error
In Node.js 8 and below, the request object would be destroyed and be left in non-readable state (i.e. req.readable === false ).
Read more >Add Retries to HTTP requests - DEV Community
Whether you're making API calls from Node.js or in the browser, connection failures are going to happen eventually. Some request errors are ...
Read more >node.js - nodejs - first argument must be a string or Buffer
As the error message says, write expects a string or Buffer object, so you must ... request({ uri: 'http://www.google.com', method: 'GET', ...
Read more >HTTP | Node.js v19.3.0 Documentation
maxSockets <number> Maximum number of sockets to allow per host. If the same host opens multiple concurrent connections, each request will use new...
Read more >How To Create a Web Server in Node.js with the HTTP Module
This function is meant to handle an incoming HTTP request and return an HTTP response. This function must have two arguments, a request...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’ve opened #1868 with two new tests.
🎉 This issue has been resolved in version 11.8.0 🎉
The release is available on:
Your semantic-release bot 📦🚀