Error: Protocol "http:" not supported. Expected "https:"
See original GitHub issueI am trying to mock all requests to a specific domain, excluding a single request based on body vars.
Using the following nock code:
nock('https://www.example.com', { allowUnmocked: true })
.persist()
.post('/api/method', (body) => {
// here is a check for the presence of a certain body variable
// returning false for example purposes
return false;
})
.reply(200, {
success: true,
});
The result error is:
Error: Protocol "http:" not supported. Expected "https:"
I have tried it both with axios and request to ensure that it’s not an axios issue.
Stack trace while using axios:
at new ClientRequest (_http_client.js:54:11)
at end (node_modules/nock/lib/request_overrider.js:257:24)
at OverriddenClientRequest.RequestOverrider.req.end (node_modules/nock/lib/request_overrider.js:165:7)
at Writable.RedirectableRequest.end (node_modules/follow-redirects/index.js:203:23)
at dispatchHttpRequest (node_modules/axios/lib/adapters/http.js:228:11)
at httpAdapter (node_modules/axios/lib/adapters/http.js:18:10)
at dispatchRequest (node_modules/axios/lib/core/dispatchRequest.js:52:10)
at process._tickDomainCallback (internal/process/next_tick.js:135:7)
Stack trace while using request:
at new ClientRequest (_http_client.js:54:11)
at end (node_modules/nock/lib/request_overrider.js:257:24)
at OverriddenClientRequest.RequestOverrider.req.end (node_modules/nock/lib/request_overrider.js:165:7)
at Request.end (node_modules/request/request.js:1515:14)
at end (node_modules/request/request.js:548:16)
at Immediate.<anonymous> (node_modules/request/request.js:575:7)
nock: 9.0.15
axios: 0.16.2
request: 2.82.0
node: 6.11.3
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Node js Error: Protocol "https:" not supported. Expected "http:"
The reason for this error is that you are trying to call a HTTPS URI from a HTTP client. The ideal ...
Read more >Protocol "http:" not supported. Expected "https:" · Issue #263 ...
The issue is that relative URLs do not exist in NodeJS. All requests in NodeJS must have an absolute URL (either explicit or...
Read more >Node js Error: Protocol "https:" not supported. Expected "http:"
JavaScript : Node js Error : Protocol " https :" not supported. Expected " http :" [ Gift : Animated Search Engine :...
Read more >Protocol "http:" not supported. Expected "https:"
In my application when I try to login with Auth0, I get the following error and the login fails. Protocol "http:" not supported....
Read more >3226597 - Fiori application cannot be started from Business ...
In the terminal where the application is started the following error message is ... TypeError [ERR_INVALID_PROTOCOL]: Protocol "https:" not supported.
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 did some digging on the code, the issue starts from the point where it looks for a match without checking the body.
https://github.com/node-nock/nock/blob/c82715bd8f1cf90244bae120272c8c022ed44754/lib/intercept.js#L357-L359
Anyway I did a workaround for my scenario, using
.cleanAll()right before running the request that has to go through.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!