Comments (14)
Important to note is that the same code, but with an external host, works perfect:
http = require 'http'
nock = require 'nock'
options =
host: 'www.google.be',
port: 80,
path: '/'
http.get options, (error, reply) ->
console.log error
console.log reply
from nock.
+1. I have the exact same problem, just killed an hour+ looking for it in other libraries.
Happy to take a workaround...
from nock.
FYI, problem first appears in 0.10.6. I tried everything from 0.10.1 (where it used to work for me), up to 0.10.8, and it appears with 0.10.6
from nock.
And one more for you: It only occurs when you specify a port other than 80 on the http.get. Specifying port 80 or no port works:
var http = require('http');
require('nock');
http.get({host:"localhost"}, function(res) {
console.log("NOPORT response: " + res.statusCode);
}).on('error', function(e) {
console.log("NOPORT error: " + e.message);
});
http.get({host:"localhost",port:80}, function(res) {
console.log("PORT80 response: " + res.statusCode);
}).on('error', function(e) {
console.log("PORT80 error: " + e.message);
});
http.get({host:"localhost",port:81}, function(res) {
console.log("PORT81 response: " + res.statusCode);
}).on('error', function(e) {
console.log("PORT81 error: " + e.message);
});
Will give the following output:
PORT81 error: getaddrinfo ENOENT
PORT80 response: success
NOPORT response: success
It appears to have something to do with commit 8797e28
from nock.
I got it. It is that one. And the problem is in intercept.js LL42-64 or LL 93-134.
Here is what is wrong. In line 93-134 (or so), http.request is overridden. Makes sense. Then nock checks if it has interceptorsFor given the options. If it finds, it uses those, else it just launches the oldRequest.
BUT: if it is anything other than a non-standard port (http:80 or https:443), it changes the original options object. So if options was the first part, it transforms to the second part
{host:"localhost",port:80} -> {host:"localhost",port:80}
{host:"localhost",port:81} -> {host:"localhost:81"} // here is the problem
It then finds no interceptor and passes the request on to oldRequest, but it now changed the original options.
What it should do is duplicate the options, then modify those, so that the original stays.
from nock.
Thanks for the report, released nock v0.11.4
from nock.
Speedy!
Still got a different bug. Look at intercept.js L69:
console.log('basePath:', basePath)
I don't think you want that console.log in release... :-)
from nock.
Oops, thanks for noticing it, removed in nock v0.11.5.
from nock.
No prob. Putting in.
"nock":">=0.11.5"
now.
On Mar 28, 2012, at 11:05 AM, Pedro Teixeira
[email protected]
wrote:
Oops, thanks for noticing it, removed in nock v0.11.5.
Reply to this email directly or view it on GitHub:
#52 (comment)
from nock.
Thank you pgte & deitch for working out a solution!
from nock.
Pleasure. Glad I was able to find it and proffer a solution, rather than just complain, "it doesn't work!" :-)
Just tested 0.11.5 and works great.
from nock.
Yes, that type of report is great, helped a lot.
The only best thing is a pull request with the fix ;)
from nock.
Ok, true, but it seemed silly to do a whole clone/fix/pull just for that.
Well, maybe not; next time... :-)
On Fri, Mar 30, 2012 at 9:22 AM, Pedro Teixeira <
[email protected]
wrote:
Yes, that type of report is great, helped a lot.
The only best thing is a pull request with the fix ;)
Reply to this email directly or view it on GitHub:
#52 (comment)
from nock.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue and add a reference to this one if itβs related. Thank you!
from nock.
Related Issues (20)
- Incompatible with node 18 HOT 7
- Support AbortSignal in http requests
- Convenience method to match all HTTP verbs
- enableNetConnect does not work w nock.recorder.rec() HOT 1
- [Node 18.12] Class extends value undefined is not a constructor or null HOT 2
- incompatible behaviour introduced with v13.3.2 HOT 17
- Interceptors not being removed in 13.3.2 HOT 2
- Replace npm debug with require('node:util').debuglog HOT 2
- Remove lodash HOT 1
- Application to become a nock maintainer. HOT 5
- Expand function fails on weird GET query params HOT 4
- reqheaders does not work when using an undefined requestBody HOT 3
- Add interceptor at the beginning of list
- Return 500 instead of 404 HOT 4
- Bun support for nock.disableNetConnect() HOT 1
- DNS resolve errors and not mocking a lot of requests HOT 7
- POST request with ReadStream request body does not return a response HOT 10
- Disabled discussions HOT 6
- Improve debug logging HOT 2
- Support Abort Signals HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nock.